diff options
author | Kozlov Dmitry <dima@server> | 2010-10-05 17:51:23 +0400 |
---|---|---|
committer | Kozlov Dmitry <dima@server> | 2010-10-05 17:51:23 +0400 |
commit | 5cf93f33f2350ed3b92f73ead1d2829a6883810a (patch) | |
tree | ab1d7fe7b27ca44ef3ee6618636d275c26f98c76 /accel-pptpd/auth | |
parent | 7f16563bd5a4ef21b970e8dcbab0e5cbe02bfe97 (diff) | |
download | accel-ppp-5cf93f33f2350ed3b92f73ead1d2829a6883810a.tar.gz accel-ppp-5cf93f33f2350ed3b92f73ead1d2829a6883810a.zip |
tidied logs
Diffstat (limited to 'accel-pptpd/auth')
-rw-r--r-- | accel-pptpd/auth/auth_chap_md5.c | 173 | ||||
-rw-r--r-- | accel-pptpd/auth/auth_mschap_v1.c | 221 | ||||
-rw-r--r-- | accel-pptpd/auth/auth_mschap_v2.c | 184 | ||||
-rw-r--r-- | accel-pptpd/auth/auth_pap.c | 115 |
4 files changed, 358 insertions, 335 deletions
diff --git a/accel-pptpd/auth/auth_chap_md5.c b/accel-pptpd/auth/auth_chap_md5.c index e0fe2d4..4031a9a 100644 --- a/accel-pptpd/auth/auth_chap_md5.c +++ b/accel-pptpd/auth/auth_chap_md5.c @@ -84,49 +84,49 @@ static void chap_recv(struct ppp_handler_t *h); static void chap_timeout(struct triton_timer_t *t); static void chap_restart(struct triton_timer_t *t); -static void print_buf(const uint8_t *buf,int size) +static void print_buf(const uint8_t *buf, int size) { int i; - for(i=0;i<size;i++) - log_ppp_debug("%x",buf[i]); + for (i=0; i < size; i++) + log_ppp_info("%x", buf[i]); } -static void print_str(const char *buf,int size) +static void print_str(const char *buf, int size) { int i; - for(i=0;i<size;i++) - log_ppp_debug("%c",buf[i]); + for (i = 0; i < size; i++) + log_ppp_info("%c", buf[i]); } static struct auth_data_t* auth_data_init(struct ppp_t *ppp) { - struct chap_auth_data_t *d=_malloc(sizeof(*d)); + struct chap_auth_data_t *d = _malloc(sizeof(*d)); - memset(d,0,sizeof(*d)); - d->auth.proto=PPP_CHAP; - d->ppp=ppp; + memset(d, 0, sizeof(*d)); + d->auth.proto = PPP_CHAP; + d->ppp = ppp; return &d->auth; } -static void auth_data_free(struct ppp_t *ppp,struct auth_data_t *auth) +static void auth_data_free(struct ppp_t *ppp, struct auth_data_t *auth) { - struct chap_auth_data_t *d=container_of(auth,typeof(*d),auth); + struct chap_auth_data_t *d = container_of(auth, typeof(*d), auth); _free(d); } static int chap_start(struct ppp_t *ppp, struct auth_data_t *auth) { - struct chap_auth_data_t *d=container_of(auth,typeof(*d),auth); + struct chap_auth_data_t *d = container_of(auth, typeof(*d), auth); - d->h.proto=PPP_CHAP; - d->h.recv=chap_recv; + d->h.proto = PPP_CHAP; + d->h.recv = chap_recv; d->timeout.expire = chap_timeout; d->timeout.period = conf_timeout * 1000; d->interval.expire = chap_restart; d->interval.period = conf_interval * 1000; - ppp_register_chan_handler(ppp,&d->h); + ppp_register_chan_handler(ppp, &d->h); chap_send_challenge(d); @@ -135,7 +135,7 @@ static int chap_start(struct ppp_t *ppp, struct auth_data_t *auth) static int chap_finish(struct ppp_t *ppp, struct auth_data_t *auth) { - struct chap_auth_data_t *d=container_of(auth,typeof(*d),auth); + struct chap_auth_data_t *d = container_of(auth, typeof(*d), auth); if (d->timeout.tpd) triton_timer_del(&d->timeout); @@ -143,7 +143,7 @@ static int chap_finish(struct ppp_t *ppp, struct auth_data_t *auth) if (d->interval.tpd) triton_timer_del(&d->interval); - ppp_unregister_handler(ppp,&d->h); + ppp_unregister_handler(ppp, &d->h); return 0; } @@ -152,7 +152,8 @@ static void chap_timeout(struct triton_timer_t *t) { struct chap_auth_data_t *d = container_of(t, typeof(*d), timeout); - log_ppp_warn("chap-md5: timeout\n"); + if (conf_ppp_verbose) + log_ppp_warn("chap-md5: timeout\n"); if (++d->failure == conf_max_failure) { if (d->started) @@ -187,55 +188,56 @@ static int lcp_recv_conf_req(struct ppp_t *ppp, struct auth_data_t *d, uint8_t * static void chap_send_failure(struct chap_auth_data_t *ad) { - struct chap_failure_t msg= - { - .hdr.proto=htons(PPP_CHAP), - .hdr.code=CHAP_FAILURE, - .hdr.id=ad->id, - .hdr.len=htons(sizeof(msg)-1-2), - .message=MSG_FAILURE, + struct chap_failure_t msg = { + .hdr.proto = htons(PPP_CHAP), + .hdr.code = CHAP_FAILURE, + .hdr.id = ad->id, + .hdr.len = htons(sizeof(msg) - 1 - 2), + .message = MSG_FAILURE, }; - log_ppp_debug("send [CHAP Failure id=%x \"%s\"]\n",msg.hdr.id,MSG_FAILURE); + if (conf_ppp_verbose) + log_ppp_info("send [CHAP Failure id=%x \"%s\"]\n", msg.hdr.id, MSG_FAILURE); - ppp_chan_send(ad->ppp,&msg,ntohs(msg.hdr.len)+2); + ppp_chan_send(ad->ppp, &msg, ntohs(msg.hdr.len) + 2); } static void chap_send_success(struct chap_auth_data_t *ad) { - struct chap_success_t msg= - { - .hdr.proto=htons(PPP_CHAP), - .hdr.code=CHAP_SUCCESS, - .hdr.id=ad->id, - .hdr.len=htons(sizeof(msg)-1-2), - .message=MSG_SUCCESS, + struct chap_success_t msg = { + .hdr.proto = htons(PPP_CHAP), + .hdr.code = CHAP_SUCCESS, + .hdr.id = ad->id, + .hdr.len = htons(sizeof(msg)-1-2), + .message = MSG_SUCCESS, }; - log_ppp_debug("send [CHAP Success id=%x \"%s\"]\n",msg.hdr.id,MSG_SUCCESS); + if (conf_ppp_verbose) + log_ppp_info("send [CHAP Success id=%x \"%s\"]\n", msg.hdr.id, MSG_SUCCESS); - ppp_chan_send(ad->ppp,&msg,ntohs(msg.hdr.len)+2); + ppp_chan_send(ad->ppp, &msg, ntohs(msg.hdr.len) + 2); } static void chap_send_challenge(struct chap_auth_data_t *ad) { - struct chap_challenge_t msg= - { - .hdr.proto=htons(PPP_CHAP), - .hdr.code=CHAP_CHALLENGE, - .hdr.id=++ad->id, - .hdr.len=htons(sizeof(msg)-2), - .val_size=VALUE_SIZE, + struct chap_challenge_t msg = { + .hdr.proto = htons(PPP_CHAP), + .hdr.code = CHAP_CHALLENGE, + .hdr.id = ++ad->id, + .hdr.len = htons(sizeof(msg) - 2), + .val_size = VALUE_SIZE, }; - read(urandom_fd,ad->val,VALUE_SIZE); - memcpy(msg.val,ad->val,VALUE_SIZE); + read(urandom_fd, ad->val, VALUE_SIZE); + memcpy(msg.val, ad->val, VALUE_SIZE); - log_ppp_debug("send [CHAP Challenge id=%x <",msg.hdr.id); - print_buf(msg.val,VALUE_SIZE); - log_ppp_debug(">]\n"); + if (conf_ppp_verbose) { + log_ppp_info("send [CHAP Challenge id=%x <", msg.hdr.id); + print_buf(msg.val, VALUE_SIZE); + log_ppp_info(">]\n"); + } - ppp_chan_send(ad->ppp,&msg,ntohs(msg.hdr.len)+2); + ppp_chan_send(ad->ppp, &msg, ntohs(msg.hdr.len) + 2); if (conf_timeout && !ad->timeout.tpd) triton_timer_add(ad->ppp->ctrl->ctx, &ad->timeout, 0); @@ -248,32 +250,33 @@ static void chap_recv_response(struct chap_auth_data_t *ad, struct chap_hdr_t *h char *passwd; char *name; int r; - struct chap_challenge_t *msg=(struct chap_challenge_t*)hdr; + struct chap_challenge_t *msg = (struct chap_challenge_t*)hdr; if (ad->timeout.tpd) triton_timer_del(&ad->timeout); - log_ppp_debug("recv [CHAP Response id=%x <", msg->hdr.id); - print_buf(msg->val,msg->val_size); - log_ppp_debug(">, name=\""); - print_str(msg->name,ntohs(msg->hdr.len)-sizeof(*msg)+2); - log_ppp_debug("\"]\n"); + if (conf_ppp_verbose) { + log_ppp_info("recv [CHAP Response id=%x <", msg->hdr.id); + print_buf(msg->val, msg->val_size); + log_ppp_info(">, name=\""); + print_str(msg->name, ntohs(msg->hdr.len) - sizeof(*msg) + 2); + log_ppp_info("\"]\n"); + } - if (msg->hdr.id!=ad->id) - { - log_ppp_error("chap-md5: id mismatch\n"); + if (msg->hdr.id != ad->id) { + if (conf_ppp_verbose) + log_ppp_error("chap-md5: id mismatch\n"); chap_send_failure(ad); ppp_terminate(ad->ppp, 0); } - if (msg->val_size!=VALUE_SIZE) - { - log_ppp_error("chap-md5: value-size should be %i, expected %i\n",VALUE_SIZE,msg->val_size); + if (msg->val_size != VALUE_SIZE) { + log_ppp_error("chap-md5: incorrect value-size (%i)\n", msg->val_size); chap_send_failure(ad); ppp_terminate(ad->ppp, 0); } - name = _strndup(msg->name,ntohs(msg->hdr.len)-sizeof(*msg)+2); + name = _strndup(msg->name,ntohs(msg->hdr.len) - sizeof(*msg) + 2); r = pwdb_check(ad->ppp, name, PPP_CHAP, CHAP_MD5, ad->id, ad->val, VALUE_SIZE, msg->val); @@ -282,7 +285,8 @@ static void chap_recv_response(struct chap_auth_data_t *ad, struct chap_hdr_t *h if (!passwd) { _free(name); - log_ppp_debug("chap-md5: user not found\n"); + if (conf_ppp_verbose) + log_ppp_warn("chap-md5: user not found\n"); chap_send_failure(ad); return; } @@ -295,7 +299,8 @@ static void chap_recv_response(struct chap_auth_data_t *ad, struct chap_hdr_t *h if (memcmp(md5,msg->val,sizeof(md5))) { - log_ppp_debug("chap-md5: challenge response mismatch\n"); + if (conf_ppp_verbose) + log_ppp_warn("chap-md5: challenge response mismatch\n"); chap_send_failure(ad); if (ad->started) ppp_terminate(ad->ppp, 0); @@ -331,33 +336,37 @@ static void chap_recv_response(struct chap_auth_data_t *ad, struct chap_hdr_t *h } } +static int chap_check(uint8_t *ptr) +{ + return *ptr == CHAP_MD5; +} + static struct ppp_auth_handler_t chap= { - .name="CHAP-md5", - .init=auth_data_init, - .free=auth_data_free, - .send_conf_req=lcp_send_conf_req, - .recv_conf_req=lcp_recv_conf_req, - .start=chap_start, - .finish=chap_finish, + .name = "CHAP-md5", + .init = auth_data_init, + .free = auth_data_free, + .send_conf_req = lcp_send_conf_req, + .recv_conf_req = lcp_recv_conf_req, + .start = chap_start, + .finish = chap_finish, + .check = chap_check, }; static void chap_recv(struct ppp_handler_t *h) { - struct chap_auth_data_t *d=container_of(h,typeof(*d),h); - struct chap_hdr_t *hdr=(struct chap_hdr_t *)d->ppp->chan_buf; + struct chap_auth_data_t *d = container_of(h, typeof(*d), h); + struct chap_hdr_t *hdr = (struct chap_hdr_t *)d->ppp->chan_buf; - if (d->ppp->chan_buf_size<sizeof(*hdr) || ntohs(hdr->len)<HDR_LEN || ntohs(hdr->len)<d->ppp->chan_buf_size-2) - { - log_ppp_warn("CHAP: short packet received\n"); + if (d->ppp->chan_buf_size < sizeof(*hdr) || ntohs(hdr->len) < HDR_LEN || ntohs(hdr->len) < d->ppp->chan_buf_size - 2) { + log_ppp_warn("chap-md5: short packet received\n"); return; } - if (hdr->code==CHAP_RESPONSE) chap_recv_response(d,hdr); + if (hdr->code == CHAP_RESPONSE) + chap_recv_response(d, hdr); else - { - log_ppp_warn("CHAP: unknown code received %x\n",hdr->code); - } + log_ppp_warn("chap-md5: unknown code received %x\n", hdr->code); } static void __init auth_chap_md5_init() @@ -384,6 +393,6 @@ static void __init auth_chap_md5_init() } if (ppp_auth_register_handler(&chap)) - log_error("chap-md5: failed to register handler\n"); + log_emerg("chap-md5: failed to register handler\n"); } diff --git a/accel-pptpd/auth/auth_mschap_v1.c b/accel-pptpd/auth/auth_mschap_v1.c index 203c25e..5b4935e 100644 --- a/accel-pptpd/auth/auth_mschap_v1.c +++ b/accel-pptpd/auth/auth_mschap_v1.c @@ -101,46 +101,46 @@ static void chap_restart(struct triton_timer_t *t); static void print_buf(const uint8_t *buf,int size) { int i; - for(i=0;i<size;i++) - log_ppp_debug("%x",buf[i]); + for (i = 0; i < size; i++) + log_ppp_info("%x", buf[i]); } -static void print_str(const char *buf,int size) +static void print_str(const char *buf, int size) { int i; - for(i=0;i<size;i++) - log_ppp_debug("%c",buf[i]); + for(i = 0; i < size; i++) + log_ppp_info("%c", buf[i]); } static struct auth_data_t* auth_data_init(struct ppp_t *ppp) { - struct chap_auth_data_t *d=_malloc(sizeof(*d)); + struct chap_auth_data_t *d = _malloc(sizeof(*d)); - memset(d,0,sizeof(*d)); - d->auth.proto=PPP_CHAP; - d->ppp=ppp; + memset(d, 0, sizeof(*d)); + d->auth.proto = PPP_CHAP; + d->ppp = ppp; return &d->auth; } -static void auth_data_free(struct ppp_t *ppp,struct auth_data_t *auth) +static void auth_data_free(struct ppp_t *ppp, struct auth_data_t *auth) { - struct chap_auth_data_t *d=container_of(auth,typeof(*d),auth); + struct chap_auth_data_t *d = container_of(auth, typeof(*d), auth); _free(d); } static int chap_start(struct ppp_t *ppp, struct auth_data_t *auth) { - struct chap_auth_data_t *d=container_of(auth,typeof(*d),auth); + struct chap_auth_data_t *d = container_of(auth, typeof(*d), auth); - d->h.proto=PPP_CHAP; - d->h.recv=chap_recv; + d->h.proto = PPP_CHAP; + d->h.recv = chap_recv; d->timeout.expire = chap_timeout; d->timeout.period = conf_timeout * 1000; d->interval.expire = chap_restart; d->interval.period = conf_interval * 1000; - ppp_register_chan_handler(ppp,&d->h); + ppp_register_chan_handler(ppp, &d->h); chap_send_challenge(d); @@ -149,7 +149,7 @@ static int chap_start(struct ppp_t *ppp, struct auth_data_t *auth) static int chap_finish(struct ppp_t *ppp, struct auth_data_t *auth) { - struct chap_auth_data_t *d=container_of(auth,typeof(*d),auth); + struct chap_auth_data_t *d = container_of(auth, typeof(*d), auth); if (d->timeout.tpd) triton_timer_del(&d->timeout); @@ -157,7 +157,7 @@ static int chap_finish(struct ppp_t *ppp, struct auth_data_t *auth) if (d->interval.tpd) triton_timer_del(&d->interval); - ppp_unregister_handler(ppp,&d->h); + ppp_unregister_handler(ppp, &d->h); return 0; } @@ -166,7 +166,8 @@ static void chap_timeout(struct triton_timer_t *t) { struct chap_auth_data_t *d = container_of(t, typeof(*d), timeout); - log_ppp_warn("mschap-v1: timeout\n"); + if (conf_ppp_verbose) + log_ppp_warn("mschap-v1: timeout\n"); if (++d->failure == conf_max_failure) { if (d->started) @@ -188,68 +189,69 @@ static void chap_restart(struct triton_timer_t *t) static int lcp_send_conf_req(struct ppp_t *ppp, struct auth_data_t *d, uint8_t *ptr) { - *ptr=MSCHAP_V1; + *ptr = MSCHAP_V1; return 1; } static int lcp_recv_conf_req(struct ppp_t *ppp, struct auth_data_t *d, uint8_t *ptr) { - if (*ptr==MSCHAP_V1) + if (*ptr == MSCHAP_V1) return LCP_OPT_ACK; return LCP_OPT_NAK; } static void chap_send_failure(struct chap_auth_data_t *ad) { - struct chap_failure_t msg= - { - .hdr.proto=htons(PPP_CHAP), - .hdr.code=CHAP_FAILURE, - .hdr.id=ad->id, - .hdr.len=htons(sizeof(msg)-1-2), - .message=MSG_FAILURE, + struct chap_failure_t msg = { + .hdr.proto = htons(PPP_CHAP), + .hdr.code = CHAP_FAILURE, + .hdr.id = ad->id, + .hdr.len = htons(sizeof(msg)-1-2), + .message = MSG_FAILURE, }; - log_ppp_debug("send [MSCHAP-v1 Failure id=%x \"%s\"]\n",msg.hdr.id,MSG_FAILURE); + if (conf_ppp_verbose) + log_ppp_info("send [MSCHAP-v1 Failure id=%x \"%s\"]\n", msg.hdr.id, MSG_FAILURE); ppp_chan_send(ad->ppp,&msg,ntohs(msg.hdr.len)+2); } static void chap_send_success(struct chap_auth_data_t *ad) { - struct chap_success_t msg= - { - .hdr.proto=htons(PPP_CHAP), - .hdr.code=CHAP_SUCCESS, - .hdr.id=ad->id, - .hdr.len=htons(sizeof(msg)-1-2), - .message=MSG_SUCCESS, + struct chap_success_t msg = { + .hdr.proto = htons(PPP_CHAP), + .hdr.code = CHAP_SUCCESS, + .hdr.id = ad->id, + .hdr.len = htons(sizeof(msg)-1-2), + .message = MSG_SUCCESS, }; - log_ppp_debug("send [MSCHAP-v1 Success id=%x \"%s\"]\n",msg.hdr.id,MSG_SUCCESS); + if (conf_ppp_verbose) + log_ppp_info("send [MSCHAP-v1 Success id=%x \"%s\"]\n", msg.hdr.id, MSG_SUCCESS); - ppp_chan_send(ad->ppp,&msg,ntohs(msg.hdr.len)+2); + ppp_chan_send(ad->ppp, &msg, ntohs(msg.hdr.len) + 2); } static void chap_send_challenge(struct chap_auth_data_t *ad) { - struct chap_challenge_t msg= - { - .hdr.proto=htons(PPP_CHAP), - .hdr.code=CHAP_CHALLENGE, - .hdr.id=++ad->id, - .hdr.len=htons(sizeof(msg)-2), - .val_size=VALUE_SIZE, + struct chap_challenge_t msg = { + .hdr.proto = htons(PPP_CHAP), + .hdr.code = CHAP_CHALLENGE, + .hdr.id = ++ad->id, + .hdr.len = htons(sizeof(msg) - 2), + .val_size = VALUE_SIZE, }; - read(urandom_fd,ad->val,VALUE_SIZE); - memcpy(msg.val,ad->val,VALUE_SIZE); + read(urandom_fd, ad->val, VALUE_SIZE); + memcpy(msg.val, ad->val, VALUE_SIZE); - log_ppp_debug("send [MSCHAP-v1 Challenge id=%x <",msg.hdr.id); - print_buf(msg.val,VALUE_SIZE); - log_ppp_debug(">]\n"); + if (conf_ppp_verbose) { + log_ppp_info("send [MSCHAP-v1 Challenge id=%x <", msg.hdr.id); + print_buf(msg.val, VALUE_SIZE); + log_ppp_info(">]\n"); + } - ppp_chan_send(ad->ppp,&msg,ntohs(msg.hdr.len)+2); + ppp_chan_send(ad->ppp, &msg, ntohs(msg.hdr.len) + 2); if (conf_timeout && !ad->timeout.tpd) triton_timer_add(ad->ppp->ctrl->ctx, &ad->timeout, 0); @@ -257,24 +259,26 @@ static void chap_send_challenge(struct chap_auth_data_t *ad) static void chap_recv_response(struct chap_auth_data_t *ad, struct chap_hdr_t *hdr) { - struct chap_response_t *msg=(struct chap_response_t*)hdr; + struct chap_response_t *msg = (struct chap_response_t*)hdr; char *name; int r; if (ad->timeout.tpd) triton_timer_del(&ad->timeout); - log_ppp_debug("recv [MSCHAP-v1 Response id=%x <", msg->hdr.id); - print_buf(msg->lm_hash,24); - log_ppp_debug(">, <"); - print_buf(msg->nt_hash,24); - log_ppp_debug(">, F=%i, name=\"",msg->flags); - print_str(msg->name,ntohs(msg->hdr.len)-sizeof(*msg)+2); - log_ppp_debug("\"]\n"); + if (conf_ppp_verbose) { + log_ppp_info("recv [MSCHAP-v1 Response id=%x <", msg->hdr.id); + print_buf(msg->lm_hash, 24); + log_ppp_info(">, <"); + print_buf(msg->nt_hash, 24); + log_ppp_info(">, F=%i, name=\"", msg->flags); + print_str(msg->name, ntohs(msg->hdr.len) - sizeof(*msg) + 2); + log_ppp_info("\"]\n"); + } - if (msg->hdr.id!=ad->id) - { - log_ppp_error("mschap-v1: id mismatch\n"); + if (msg->hdr.id != ad->id) { + if (conf_ppp_verbose) + log_ppp_error("mschap-v1: id mismatch\n"); chap_send_failure(ad); if (ad->started) ppp_terminate(ad->ppp, 0); @@ -282,9 +286,8 @@ static void chap_recv_response(struct chap_auth_data_t *ad, struct chap_hdr_t *h auth_failed(ad->ppp); } - if (msg->val_size!=RESPONSE_VALUE_SIZE) - { - log_ppp_error("mschap-v1: value-size should be %i, expected %i\n",RESPONSE_VALUE_SIZE,msg->val_size); + if (msg->val_size != RESPONSE_VALUE_SIZE) { + log_ppp_error("mschap-v1: incorrect value-size (%i)\n", msg->val_size); chap_send_failure(ad); if (ad->started) ppp_terminate(ad->ppp, 0); @@ -292,7 +295,7 @@ static void chap_recv_response(struct chap_auth_data_t *ad, struct chap_hdr_t *h auth_failed(ad->ppp); } - name = _strndup(msg->name,ntohs(msg->hdr.len)-sizeof(*msg)+2); + name = _strndup(msg->name, ntohs(msg->hdr.len) - sizeof(*msg) + 2); if (!name) { log_emerg("mschap-v1: out of memory\n"); if (ad->started) @@ -326,7 +329,7 @@ static void chap_recv_response(struct chap_auth_data_t *ad, struct chap_hdr_t *h static void des_encrypt(const uint8_t *input, const uint8_t *key, uint8_t *output) { - int i,j,parity; + int i, j, parity; union { uint64_t u64; @@ -336,21 +339,21 @@ static void des_encrypt(const uint8_t *input, const uint8_t *key, uint8_t *outpu DES_cblock res; DES_key_schedule ks; - memcpy(p_key.buf,key,7); - p_key.u64=bswap_64(p_key.u64); + memcpy(p_key.buf, key, 7); + p_key.u64 = bswap_64(p_key.u64); - for(i=0;i<8;i++) - { - cb[i]=(((p_key.u64<<(7*i))>>56)&0xfe); - for(j=0, parity=0; j<7; j++) - if ((cb[i]>>(j+1))&1) parity++; - cb[i]|=(~parity)&1; + for (i = 0; i < 8; i++) { + cb[i] = (((p_key.u64 << (7 * i)) >> 56) & 0xfe); + for( j = 0, parity = 0; j < 7; j++) + if ((cb[i] >> (j + 1)) & 1) + parity++; + cb[i] |= (~parity) & 1; } DES_set_key_checked(&cb, &ks); - memcpy(cb,input,8); - DES_ecb_encrypt(&cb,&res,&ks,DES_ENCRYPT); - memcpy(output,res,8); + memcpy(cb, input, 8); + DES_ecb_encrypt(&cb, &res, &ks, DES_ENCRYPT); + memcpy(output, res, 8); } static int chap_check_response(struct chap_auth_data_t *ad, struct chap_response_t *msg, const char *name) @@ -363,62 +366,64 @@ static int chap_check_response(struct chap_auth_data_t *ad, struct chap_response int i; passwd = pwdb_get_passwd(ad->ppp,name); - if (!passwd) - { - log_ppp_debug("mschap-v1: user not found\n"); + if (!passwd) { + if (conf_ppp_verbose) + log_ppp_warn("mschap-v1: user not found\n"); chap_send_failure(ad); return PWDB_DENIED; } - u_passwd=_malloc(strlen(passwd)*2); - for(i=0; i<strlen(passwd); i++) - { - u_passwd[i*2]=passwd[i]; - u_passwd[i*2+1]=0; + u_passwd = _malloc(strlen(passwd) * 2); + for (i = 0; i< strlen(passwd); i++) { + u_passwd[i * 2] = passwd[i]; + u_passwd[i * 2 + 1] = 0; } - memset(z_hash,0,sizeof(z_hash)); + memset(z_hash, 0, sizeof(z_hash)); MD4_Init(&md4_ctx); - MD4_Update(&md4_ctx,u_passwd,strlen(passwd)*2); - MD4_Final(z_hash,&md4_ctx); + MD4_Update(&md4_ctx, u_passwd, strlen(passwd) * 2); + MD4_Final(z_hash, &md4_ctx); - des_encrypt(ad->val,z_hash,nt_hash); - des_encrypt(ad->val,z_hash+7,nt_hash+8); - des_encrypt(ad->val,z_hash+14,nt_hash+16); + des_encrypt(ad->val, z_hash, nt_hash); + des_encrypt(ad->val, z_hash + 7, nt_hash + 8); + des_encrypt(ad->val, z_hash + 14, nt_hash + 16); _free(passwd); _free(u_passwd); - return memcmp(nt_hash,msg->nt_hash,24) ? PWDB_DENIED : PWDB_SUCCESS; + return memcmp(nt_hash, msg->nt_hash, 24) ? PWDB_DENIED : PWDB_SUCCESS; } -static struct ppp_auth_handler_t chap= +static int chap_check(uint8_t *ptr) { - .name="MSCHAP-v1", - .init=auth_data_init, - .free=auth_data_free, - .send_conf_req=lcp_send_conf_req, - .recv_conf_req=lcp_recv_conf_req, - .start=chap_start, - .finish=chap_finish, + return *ptr == MSCHAP_V1; +} + +static struct ppp_auth_handler_t chap = { + .name = "MSCHAP-v1", + .init = auth_data_init, + .free = auth_data_free, + .send_conf_req = lcp_send_conf_req, + .recv_conf_req = lcp_recv_conf_req, + .start = chap_start, + .finish = chap_finish, + .check = chap_check, }; static void chap_recv(struct ppp_handler_t *h) { - struct chap_auth_data_t *d=container_of(h,typeof(*d),h); - struct chap_hdr_t *hdr=(struct chap_hdr_t *)d->ppp->chan_buf; + struct chap_auth_data_t *d = container_of(h, typeof(*d), h); + struct chap_hdr_t *hdr = (struct chap_hdr_t *)d->ppp->chan_buf; - if (d->ppp->chan_buf_size<sizeof(*hdr) || ntohs(hdr->len)<HDR_LEN || ntohs(hdr->len)<d->ppp->chan_buf_size-2) - { + if (d->ppp->chan_buf_size < sizeof(*hdr) || ntohs(hdr->len) < HDR_LEN || ntohs(hdr->len) < d->ppp->chan_buf_size - 2) { log_ppp_warn("mschap-v1: short packet received\n"); return; } - if (hdr->code==CHAP_RESPONSE) chap_recv_response(d,hdr); + if (hdr->code == CHAP_RESPONSE) + chap_recv_response(d, hdr); else - { - log_ppp_warn("mschap-v1: unknown code received %x\n",hdr->code); - } + log_ppp_warn("mschap-v1: unknown code received %x\n", hdr->code); } static void __init auth_mschap_v1_init() diff --git a/accel-pptpd/auth/auth_mschap_v2.c b/accel-pptpd/auth/auth_mschap_v2.c index 44a67ca..a93fad6 100644 --- a/accel-pptpd/auth/auth_mschap_v2.c +++ b/accel-pptpd/auth/auth_mschap_v2.c @@ -112,51 +112,50 @@ static int chap_check_response(struct chap_auth_data_t *ad, struct chap_response static void chap_timeout(struct triton_timer_t *t); static void chap_restart(struct triton_timer_t *t); -static void print_buf(const uint8_t *buf,int size) +static void print_buf(const uint8_t *buf, int size) { int i; - for(i=0;i<size;i++) - log_ppp_debug("%x",buf[i]); + for (i = 0; i < size; i++) + log_ppp_info("%x", buf[i]); } -static void print_str(const char *buf,int size) + +static void print_str(const char *buf, int size) { int i; - for(i=0;i<size;i++) - log_ppp_debug("%c",buf[i]); + for (i = 0; i < size; i++) + log_ppp_info("%c", buf[i]); } - - static struct auth_data_t* auth_data_init(struct ppp_t *ppp) { - struct chap_auth_data_t *d=_malloc(sizeof(*d)); + struct chap_auth_data_t *d = _malloc(sizeof(*d)); - memset(d,0,sizeof(*d)); - d->auth.proto=PPP_CHAP; - d->ppp=ppp; + memset(d, 0, sizeof(*d)); + d->auth.proto = PPP_CHAP; + d->ppp = ppp; return &d->auth; } -static void auth_data_free(struct ppp_t *ppp,struct auth_data_t *auth) +static void auth_data_free(struct ppp_t *ppp, struct auth_data_t *auth) { - struct chap_auth_data_t *d=container_of(auth,typeof(*d),auth); + struct chap_auth_data_t *d = container_of(auth, typeof(*d), auth); _free(d); } static int chap_start(struct ppp_t *ppp, struct auth_data_t *auth) { - struct chap_auth_data_t *d=container_of(auth,typeof(*d),auth); + struct chap_auth_data_t *d = container_of(auth, typeof(*d), auth); - d->h.proto=PPP_CHAP; - d->h.recv=chap_recv; + d->h.proto = PPP_CHAP; + d->h.recv = chap_recv; d->timeout.expire = chap_timeout; d->timeout.period = conf_timeout * 1000; d->interval.expire = chap_restart; d->interval.period = conf_interval * 1000; - ppp_register_chan_handler(ppp,&d->h); + ppp_register_chan_handler(ppp, &d->h); chap_send_challenge(d); @@ -165,7 +164,7 @@ static int chap_start(struct ppp_t *ppp, struct auth_data_t *auth) static int chap_finish(struct ppp_t *ppp, struct auth_data_t *auth) { - struct chap_auth_data_t *d=container_of(auth,typeof(*d),auth); + struct chap_auth_data_t *d = container_of(auth, typeof(*d), auth); if (d->timeout.tpd) triton_timer_del(&d->timeout); @@ -182,7 +181,8 @@ static void chap_timeout(struct triton_timer_t *t) { struct chap_auth_data_t *d = container_of(t, typeof(*d), timeout); - log_ppp_warn("mschap-v2: timeout\n"); + if (conf_ppp_verbose) + log_ppp_warn("mschap-v2: timeout\n"); if (++d->failure == conf_max_failure) { if (d->started) @@ -217,18 +217,18 @@ static int lcp_recv_conf_req(struct ppp_t *ppp, struct auth_data_t *d, uint8_t * static void chap_send_failure(struct chap_auth_data_t *ad) { - struct chap_failure_t msg= - { - .hdr.proto=htons(PPP_CHAP), - .hdr.code=CHAP_FAILURE, - .hdr.id=ad->id, - .hdr.len=htons(sizeof(msg)-1-2), - .message=MSG_FAILURE, + struct chap_failure_t msg = { + .hdr.proto = htons(PPP_CHAP), + .hdr.code = CHAP_FAILURE, + .hdr.id = ad->id, + .hdr.len = htons(sizeof(msg) - 1 - 2), + .message = MSG_FAILURE, }; - log_ppp_debug("send [MSCHAP-v2 Failure id=%x \"%s\"]\n",msg.hdr.id,MSG_FAILURE); + if (conf_ppp_verbose) + log_ppp_info("send [MSCHAP-v2 Failure id=%x \"%s\"]\n", msg.hdr.id, MSG_FAILURE); - ppp_chan_send(ad->ppp,&msg,ntohs(msg.hdr.len)+2); + ppp_chan_send(ad->ppp, &msg, ntohs(msg.hdr.len) + 2); } static int generate_response(struct chap_auth_data_t *ad, struct chap_response_t *msg, const char *name, char *authenticator) @@ -290,41 +290,42 @@ static int generate_response(struct chap_auth_data_t *ad, struct chap_response_t static void chap_send_success(struct chap_auth_data_t *ad, struct chap_response_t *res_msg, const char *authenticator) { - struct chap_success_t msg= - { - .hdr.proto=htons(PPP_CHAP), - .hdr.code=CHAP_SUCCESS, - .hdr.id=ad->id, - .hdr.len=htons(sizeof(msg)-1-2), - .message=MSG_SUCCESS, + struct chap_success_t msg = { + .hdr.proto = htons(PPP_CHAP), + .hdr.code = CHAP_SUCCESS, + .hdr.id = ad->id, + .hdr.len = htons(sizeof(msg) - 1 - 2), + .message = MSG_SUCCESS, }; memcpy(msg.message + 2, authenticator, 40); - log_ppp_debug("send [MSCHAP-v2 Success id=%x \"%s\"]\n",msg.hdr.id,msg.message); + if (conf_ppp_verbose) + log_ppp_info("send [MSCHAP-v2 Success id=%x \"%s\"]\n", msg.hdr.id, msg.message); - ppp_chan_send(ad->ppp,&msg,ntohs(msg.hdr.len)+2); + ppp_chan_send(ad->ppp, &msg, ntohs(msg.hdr.len) + 2); } static void chap_send_challenge(struct chap_auth_data_t *ad) { - struct chap_challenge_t msg= - { - .hdr.proto=htons(PPP_CHAP), - .hdr.code=CHAP_CHALLENGE, - .hdr.id=++ad->id, - .hdr.len=htons(sizeof(msg)-2), - .val_size=VALUE_SIZE, + struct chap_challenge_t msg = { + .hdr.proto = htons(PPP_CHAP), + .hdr.code = CHAP_CHALLENGE, + .hdr.id = ++ad->id, + .hdr.len = htons(sizeof(msg) - 2), + .val_size = VALUE_SIZE, }; - read(urandom_fd,ad->val,VALUE_SIZE); - memcpy(msg.val,ad->val,VALUE_SIZE); + read(urandom_fd, ad->val, VALUE_SIZE); + memcpy(msg.val, ad->val, VALUE_SIZE); - log_ppp_debug("send [MSCHAP-v2 Challenge id=%x <",msg.hdr.id); - print_buf(msg.val,VALUE_SIZE); - log_ppp_debug(">]\n"); + if (conf_ppp_verbose) { + log_ppp_info("send [MSCHAP-v2 Challenge id=%x <", msg.hdr.id); + print_buf(msg.val, VALUE_SIZE); + log_ppp_info(">]\n"); + } - ppp_chan_send(ad->ppp,&msg,ntohs(msg.hdr.len)+2); + ppp_chan_send(ad->ppp, &msg, ntohs(msg.hdr.len) + 2); if (conf_timeout && !ad->timeout.tpd) triton_timer_add(ad->ppp->ctrl->ctx, &ad->timeout, 0); @@ -332,7 +333,7 @@ static void chap_send_challenge(struct chap_auth_data_t *ad) static void chap_recv_response(struct chap_auth_data_t *ad, struct chap_hdr_t *hdr) { - struct chap_response_t *msg=(struct chap_response_t*)hdr; + struct chap_response_t *msg = (struct chap_response_t*)hdr; char *name; char authenticator[40]; int r; @@ -340,17 +341,19 @@ static void chap_recv_response(struct chap_auth_data_t *ad, struct chap_hdr_t *h if (ad->timeout.tpd) triton_timer_del(&ad->timeout); - log_ppp_debug("recv [MSCHAP-v2 Response id=%x <", msg->hdr.id); - print_buf(msg->peer_challenge,16); - log_ppp_debug(">, <"); - print_buf(msg->nt_hash,24); - log_ppp_debug(">, F=%i, name=\"",msg->flags); - print_str(msg->name,ntohs(msg->hdr.len)-sizeof(*msg)+2); - log_ppp_debug("\"]\n"); + if (conf_ppp_verbose) { + log_ppp_info("recv [MSCHAP-v2 Response id=%x <", msg->hdr.id); + print_buf(msg->peer_challenge,16); + log_ppp_info(">, <"); + print_buf(msg->nt_hash, 24); + log_ppp_info(">, F=%i, name=\"", msg->flags); + print_str(msg->name, ntohs(msg->hdr.len) - sizeof(*msg) + 2); + log_ppp_info("\"]\n"); + } - if (msg->hdr.id!=ad->id) - { - log_ppp_error("mschap-v2: id mismatch\n"); + if (msg->hdr.id != ad->id) { + if (conf_ppp_verbose) + log_ppp_error("mschap-v2: id mismatch\n"); chap_send_failure(ad); if (ad->started) ppp_terminate(ad->ppp, 0); @@ -358,9 +361,8 @@ static void chap_recv_response(struct chap_auth_data_t *ad, struct chap_hdr_t *h auth_failed(ad->ppp); } - if (msg->val_size!=RESPONSE_VALUE_SIZE) - { - log_ppp_error("mschap-v2: value-size should be %i, expected %i\n",RESPONSE_VALUE_SIZE,msg->val_size); + if (msg->val_size != RESPONSE_VALUE_SIZE) { + log_ppp_error("mschap-v2: incorrect value-size (%i)\n", msg->val_size); chap_send_failure(ad); if (ad->started) ppp_terminate(ad->ppp, 0); @@ -368,7 +370,7 @@ static void chap_recv_response(struct chap_auth_data_t *ad, struct chap_hdr_t *h auth_failed(ad->ppp); } - name=_strndup(msg->name,ntohs(msg->hdr.len)-sizeof(*msg)+2); + name = _strndup(msg->name, ntohs(msg->hdr.len) - sizeof(*msg) + 2); if (!name) { log_emerg("mschap-v2: out of memory\n"); if (ad->started) @@ -444,10 +446,10 @@ static int chap_check_response(struct chap_auth_data_t *ad, struct chap_response char *u_passwd; int i; - passwd=pwdb_get_passwd(ad->ppp,name); - if (!passwd) - { - log_ppp_debug("mschap-v2: user not found\n"); + passwd = pwdb_get_passwd(ad->ppp, name); + if (!passwd) { + if (conf_ppp_verbose) + log_ppp_warn("mschap-v2: user not found\n"); chap_send_failure(ad); return -1; } @@ -480,44 +482,48 @@ static int chap_check_response(struct chap_auth_data_t *ad, struct chap_response return memcmp(nt_hash,msg->nt_hash,24); } +static int chap_check(uint8_t *ptr) +{ + return *ptr == MSCHAP_V2; +} + static struct ppp_auth_handler_t chap= { - .name="MSCHAP-v2", - .init=auth_data_init, - .free=auth_data_free, - .send_conf_req=lcp_send_conf_req, - .recv_conf_req=lcp_recv_conf_req, - .start=chap_start, - .finish=chap_finish, + .name = "MSCHAP-v2", + .init = auth_data_init, + .free = auth_data_free, + .send_conf_req = lcp_send_conf_req, + .recv_conf_req = lcp_recv_conf_req, + .start = chap_start, + .finish = chap_finish, + .check = chap_check, }; static void chap_recv(struct ppp_handler_t *h) { - struct chap_auth_data_t *d=container_of(h,typeof(*d),h); - struct chap_hdr_t *hdr=(struct chap_hdr_t *)d->ppp->chan_buf; + struct chap_auth_data_t *d = container_of(h, typeof(*d), h); + struct chap_hdr_t *hdr = (struct chap_hdr_t *)d->ppp->chan_buf; - if (d->ppp->chan_buf_size<sizeof(*hdr) || ntohs(hdr->len)<HDR_LEN || ntohs(hdr->len)<d->ppp->chan_buf_size-2) - { + if (d->ppp->chan_buf_size < sizeof(*hdr) || ntohs(hdr->len) < HDR_LEN || ntohs(hdr->len) < d->ppp->chan_buf_size - 2) { log_ppp_warn("mschap-v2: short packet received\n"); return; } - if (hdr->code==CHAP_RESPONSE) chap_recv_response(d,hdr); + if (hdr->code == CHAP_RESPONSE) + chap_recv_response(d, hdr); else - { log_ppp_warn("mschap-v2: unknown code received %x\n",hdr->code); - } } static void __init auth_mschap_v2_init() { - urandom_fd=open("/dev/urandom",O_RDONLY); - if (urandom_fd<0) - { - log_error("mschap-v2: failed to open /dev/urandom: %s\n",strerror(errno)); + urandom_fd = open("/dev/urandom", O_RDONLY); + if (urandom_fd < 0) { + log_emerg("mschap-v2: failed to open /dev/urandom: %s\n", strerror(errno)); return; } + if (ppp_auth_register_handler(&chap)) - log_error("mschap-v2: failed to register handler\n"); + log_emerg("mschap-v2: failed to register handler\n"); } diff --git a/accel-pptpd/auth/auth_pap.c b/accel-pptpd/auth/auth_pap.c index 0fd6e7f..b044f64 100644 --- a/accel-pptpd/auth/auth_pap.c +++ b/accel-pptpd/auth/auth_pap.c @@ -57,36 +57,36 @@ struct pap_ack_t static struct ppp_auth_handler_t pap= { - .name="PAP", - .init=auth_data_init, - .free=auth_data_free, - .send_conf_req=lcp_send_conf_req, - .recv_conf_req=lcp_recv_conf_req, - .start=pap_start, - .finish=pap_finish, + .name = "PAP", + .init = auth_data_init, + .free = auth_data_free, + .send_conf_req = lcp_send_conf_req, + .recv_conf_req = lcp_recv_conf_req, + .start = pap_start, + .finish = pap_finish, }; static struct auth_data_t* auth_data_init(struct ppp_t *ppp) { - struct pap_auth_data_t *d=_malloc(sizeof(*d)); + struct pap_auth_data_t *d = _malloc(sizeof(*d)); - memset(d,0,sizeof(*d)); - d->auth.proto=PPP_PAP; - d->ppp=ppp; + memset(d, 0, sizeof(*d)); + d->auth.proto = PPP_PAP; + d->ppp = ppp; return &d->auth; } -static void auth_data_free(struct ppp_t *ppp,struct auth_data_t *auth) +static void auth_data_free(struct ppp_t *ppp, struct auth_data_t *auth) { - struct pap_auth_data_t *d=container_of(auth,typeof(*d),auth); + struct pap_auth_data_t *d = container_of(auth, typeof(*d), auth); _free(d); } static int pap_start(struct ppp_t *ppp, struct auth_data_t *auth) { - struct pap_auth_data_t *d=container_of(auth,typeof(*d),auth); + struct pap_auth_data_t *d = container_of(auth, typeof(*d), auth); d->h.proto = PPP_PAP; d->h.recv = pap_recv; @@ -95,18 +95,18 @@ static int pap_start(struct ppp_t *ppp, struct auth_data_t *auth) triton_timer_add(ppp->ctrl->ctx, &d->timeout, 0); - ppp_register_chan_handler(ppp,&d->h); + ppp_register_chan_handler(ppp, &d->h); return 0; } static int pap_finish(struct ppp_t *ppp, struct auth_data_t *auth) { - struct pap_auth_data_t *d=container_of(auth,typeof(*d),auth); + struct pap_auth_data_t *d = container_of(auth, typeof(*d), auth); if (d->timeout.tpd) triton_timer_del(&d->timeout); - ppp_unregister_handler(ppp,&d->h); + ppp_unregister_handler(ppp, &d->h); return 0; } @@ -115,7 +115,9 @@ static void pap_timeout(struct triton_timer_t *t) { struct pap_auth_data_t *d = container_of(t, typeof(*d), timeout); - log_ppp_warn("pap: timeout\n"); + if (conf_ppp_verbose) + log_ppp_warn("pap: timeout\n"); + auth_failed(d->ppp); } @@ -132,36 +134,38 @@ static int lcp_recv_conf_req(struct ppp_t *ppp, struct auth_data_t *d, uint8_t * static void pap_send_ack(struct pap_auth_data_t *p, int id) { uint8_t buf[128]; - struct pap_ack_t *msg=(struct pap_ack_t*)buf; - msg->hdr.proto=htons(PPP_PAP); - msg->hdr.code=PAP_ACK; - msg->hdr.id=id; - msg->hdr.len=htons(HDR_LEN+1+sizeof(MSG_SUCCESSED)-1); - msg->msg_len=sizeof(MSG_SUCCESSED)-1; - memcpy(msg->msg,MSG_SUCCESSED,sizeof(MSG_SUCCESSED)); + struct pap_ack_t *msg = (struct pap_ack_t*)buf; + msg->hdr.proto = htons(PPP_PAP); + msg->hdr.code = PAP_ACK; + msg->hdr.id = id; + msg->hdr.len = htons(HDR_LEN + 1 + sizeof(MSG_SUCCESSED) - 1); + msg->msg_len = sizeof(MSG_SUCCESSED) - 1; + memcpy(msg->msg, MSG_SUCCESSED, sizeof(MSG_SUCCESSED)); - log_ppp_debug("send [PAP AuthAck id=%x \"%s\"]\n",id,MSG_SUCCESSED); + if (conf_ppp_verbose) + log_ppp_info("send [PAP AuthAck id=%x \"%s\"]\n", id, MSG_SUCCESSED); - ppp_chan_send(p->ppp,msg,ntohs(msg->hdr.len)+2); + ppp_chan_send(p->ppp, msg, ntohs(msg->hdr.len) + 2); } static void pap_send_nak(struct pap_auth_data_t *p, int id) { uint8_t buf[128]; - struct pap_ack_t *msg=(struct pap_ack_t*)buf; - msg->hdr.proto=htons(PPP_PAP); - msg->hdr.code=PAP_NAK; - msg->hdr.id=id; - msg->hdr.len=htons(HDR_LEN+1+sizeof(MSG_FAILED)-1); - msg->msg_len=sizeof(MSG_FAILED)-1; - memcpy(msg->msg,MSG_FAILED,sizeof(MSG_FAILED)); + struct pap_ack_t *msg = (struct pap_ack_t*)buf; + msg->hdr.proto = htons(PPP_PAP); + msg->hdr.code = PAP_NAK; + msg->hdr.id = id; + msg->hdr.len = htons(HDR_LEN + 1 + sizeof(MSG_FAILED) - 1); + msg->msg_len = sizeof(MSG_FAILED) - 1; + memcpy(msg->msg, MSG_FAILED, sizeof(MSG_FAILED)); - log_ppp_debug("send [PAP AuthNak id=%x \"%s\"]\n",id,MSG_FAILED); + if (conf_ppp_verbose) + log_ppp_info("send [PAP AuthNak id=%x \"%s\"]\n", id, MSG_FAILED); - ppp_chan_send(p->ppp,msg,ntohs(msg->hdr.len)+2); + ppp_chan_send(p->ppp, msg, ntohs(msg->hdr.len) + 2); } -static int pap_recv_req(struct pap_auth_data_t *p,struct pap_hdr_t *hdr) +static int pap_recv_req(struct pap_auth_data_t *p, struct pap_hdr_t *hdr) { int ret, r; char *peer_id; @@ -169,30 +173,29 @@ static int pap_recv_req(struct pap_auth_data_t *p,struct pap_hdr_t *hdr) const char *passwd2; int peer_id_len; int passwd_len; - uint8_t *ptr=(uint8_t*)(hdr+1); + uint8_t *ptr = (uint8_t*)(hdr + 1); if (p->timeout.tpd) triton_timer_del(&p->timeout); - log_ppp_debug("recv [PAP AuthReq id=%x]\n",hdr->id); + if (conf_ppp_verbose) + log_ppp_info("recv [PAP AuthReq id=%x]\n", hdr->id); - peer_id_len=*(uint8_t*)ptr; ptr++; - if (peer_id_len>ntohs(hdr->len)-sizeof(*hdr)+2-1) - { + peer_id_len = *(uint8_t*)ptr; ptr++; + if (peer_id_len > ntohs(hdr->len) - sizeof(*hdr) + 2 - 1) { log_ppp_warn("PAP: short packet received\n"); return -1; } - peer_id=(char*)ptr; ptr+=peer_id_len; + peer_id = (char*)ptr; ptr += peer_id_len; - passwd_len=*(uint8_t*)ptr; ptr++; - if (passwd_len>ntohs(hdr->len)-sizeof(*hdr)+2-2-peer_id_len) - { + passwd_len = *(uint8_t*)ptr; ptr++; + if (passwd_len > ntohs(hdr->len) - sizeof(*hdr ) + 2 - 2 - peer_id_len) { log_ppp_warn("PAP: short packet received\n"); return -1; } - peer_id=_strndup((const char*)peer_id,peer_id_len); - passwd=_strndup((const char*)ptr,passwd_len); + peer_id = _strndup((const char*)peer_id, peer_id_len); + passwd = _strndup((const char*)ptr, passwd_len); r = pwdb_check(p->ppp, peer_id, PPP_PAP, passwd); if (r == PWDB_NO_IMPL) { @@ -203,7 +206,8 @@ static int pap_recv_req(struct pap_auth_data_t *p,struct pap_hdr_t *hdr) r = PWDB_SUCCESS; } if (r == PWDB_DENIED) { - log_ppp_warn("PAP: authentication error\n"); + if (conf_ppp_verbose) + log_ppp_warn("PAP: authentication error\n"); pap_send_nak(p, hdr->id); if (p->started) ppp_terminate(p->ppp, 0); @@ -227,18 +231,17 @@ static int pap_recv_req(struct pap_auth_data_t *p,struct pap_hdr_t *hdr) static void pap_recv(struct ppp_handler_t *h) { - struct pap_auth_data_t *d=container_of(h,typeof(*d),h); - struct pap_hdr_t *hdr=(struct pap_hdr_t *)d->ppp->chan_buf; + struct pap_auth_data_t *d = container_of(h, typeof(*d), h); + struct pap_hdr_t *hdr = (struct pap_hdr_t *)d->ppp->chan_buf; - if (d->ppp->chan_buf_size<sizeof(*hdr) || ntohs(hdr->len)<HDR_LEN || ntohs(hdr->len)<d->ppp->chan_buf_size-2) - { + if (d->ppp->chan_buf_size < sizeof(*hdr) || ntohs(hdr->len) < HDR_LEN || ntohs(hdr->len) < d->ppp->chan_buf_size - 2) { log_ppp_warn("PAP: short packet received\n"); return; } - if (hdr->code==PAP_REQ) pap_recv_req(d,hdr); - else - { + if (hdr->code == PAP_REQ) + pap_recv_req(d, hdr); + else { log_ppp_warn("PAP: unknown code received %x\n",hdr->code); } } |