summaryrefslogtreecommitdiff
path: root/accel-pptpd/auth/auth_pap.c
diff options
context:
space:
mode:
authorKozlov Dmitry <dima@server>2010-10-05 17:51:23 +0400
committerKozlov Dmitry <dima@server>2010-10-05 17:51:23 +0400
commit5cf93f33f2350ed3b92f73ead1d2829a6883810a (patch)
treeab1d7fe7b27ca44ef3ee6618636d275c26f98c76 /accel-pptpd/auth/auth_pap.c
parent7f16563bd5a4ef21b970e8dcbab0e5cbe02bfe97 (diff)
downloadaccel-ppp-xebd-5cf93f33f2350ed3b92f73ead1d2829a6883810a.tar.gz
accel-ppp-xebd-5cf93f33f2350ed3b92f73ead1d2829a6883810a.zip
tidied logs
Diffstat (limited to 'accel-pptpd/auth/auth_pap.c')
-rw-r--r--accel-pptpd/auth/auth_pap.c115
1 files changed, 59 insertions, 56 deletions
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);
}
}