diff options
author | Kozlov Dmitry <dima@server> | 2010-09-11 14:27:27 +0400 |
---|---|---|
committer | Kozlov Dmitry <dima@server> | 2010-09-11 14:27:27 +0400 |
commit | 417ef849f1adcb3b655fbb2382e126b0b17aabbe (patch) | |
tree | 560cba379463fc8e912c7f73b54676b7c1582062 /accel-pptpd/radius | |
parent | d0c060a39d3bf6f675666a1400b533511e24a26c (diff) | |
download | accel-ppp-417ef849f1adcb3b655fbb2382e126b0b17aabbe.tar.gz accel-ppp-417ef849f1adcb3b655fbb2382e126b0b17aabbe.zip |
log: implemented extensible loggin engine with per-session logging support
log: implemented log_file logging target with per-user/per-session support
Diffstat (limited to 'accel-pptpd/radius')
-rw-r--r-- | accel-pptpd/radius/acct.c | 22 | ||||
-rw-r--r-- | accel-pptpd/radius/auth.c | 4 | ||||
-rw-r--r-- | accel-pptpd/radius/dict.c | 8 | ||||
-rw-r--r-- | accel-pptpd/radius/dm_coa.c | 20 | ||||
-rw-r--r-- | accel-pptpd/radius/packet.c | 40 | ||||
-rw-r--r-- | accel-pptpd/radius/radius.c | 8 | ||||
-rw-r--r-- | accel-pptpd/radius/req.c | 22 |
7 files changed, 68 insertions, 56 deletions
diff --git a/accel-pptpd/radius/acct.c b/accel-pptpd/radius/acct.c index 53e5e38..785eab3 100644 --- a/accel-pptpd/radius/acct.c +++ b/accel-pptpd/radius/acct.c @@ -1,4 +1,5 @@ #include <stdlib.h> +#include <stdio.h> #include <string.h> #include <errno.h> #include <unistd.h> @@ -30,10 +31,10 @@ static void req_set_stat(struct rad_req_t *req, struct ppp_t *ppp) memset(&ifreq, 0, sizeof(ifreq)); ifreq.stats_ptr = (void *)&ifreq.stats; - sprintf(ifreq.ifr__name, "ppp%i", ppp->unit_idx); + strcpy(ifreq.ifr__name, ppp->ifname); if (ioctl(sock_fd, SIOCGPPPSTATS, &ifreq)) { - log_error("radius: failed to get ppp statistics: %s\n", strerror(errno)); + log_ppp_error("radius: failed to get ppp statistics: %s\n", strerror(errno)); return; } @@ -53,8 +54,8 @@ static int rad_acct_read(struct triton_md_handler_t *h) return 0; if (conf_verbose) { - log_debug("send "); - rad_packet_print(req->reply, log_debug); + log_ppp_debug("send "); + rad_packet_print(req->reply, log_ppp_debug); } if (req->reply->code != CODE_ACCOUNTING_RESPONSE || req->reply->id != req->pack->id) { @@ -62,7 +63,6 @@ static int rad_acct_read(struct triton_md_handler_t *h) req->reply = NULL; } else { req->pack->id++; - req->timeout.period = 0; triton_timer_del(&req->timeout); } @@ -80,7 +80,7 @@ static void rad_acct_interim_update(struct triton_timer_t *t) { struct radius_pd_t *rpd = container_of(t, typeof(*rpd), acct_interim_timer); - if (rpd->acct_req->timeout.period) + if (rpd->acct_req->timeout.tpd) return; rad_packet_change_val(rpd->acct_req->pack, "Acct-Status-Type", "Interim-Update"); @@ -95,12 +95,12 @@ int rad_acct_start(struct radius_pd_t *rpd) { rpd->acct_req = rad_req_alloc(rpd, CODE_ACCOUNTING_REQUEST, rpd->ppp->username); if (!rpd->acct_req) { - log_error("radius: out of memory\n"); + log_emerg("radius: out of memory\n"); return -1; } if (rad_req_acct_fill(rpd->acct_req)) { - log_error("radius:acct: failed to fill accounting attributes\n"); + log_ppp_error("radius:acct: failed to fill accounting attributes\n"); goto out_err; } @@ -147,12 +147,12 @@ void rad_acct_stop(struct radius_pd_t *rpd) { int i; - if (rpd->acct_interim_timer.period) + if (rpd->acct_interim_timer.tpd) triton_timer_del(&rpd->acct_interim_timer); if (rpd->acct_req) { triton_md_unregister_handler(&rpd->acct_req->hnd); - if (rpd->acct_req->timeout.period) + if (rpd->acct_req->timeout.tpd) triton_timer_del(&rpd->acct_req->timeout); rad_packet_change_val(rpd->acct_req->pack, "Acct-Status-Type", "Stop"); @@ -172,7 +172,7 @@ void rad_acct_stop(struct radius_pd_t *rpd) break; } if (!rpd->acct_req->reply) - log_warn("radius:acct_stop: no response\n"); + log_ppp_warn("radius:acct_stop: no response\n"); rad_req_free(rpd->acct_req); rpd->acct_req = NULL; diff --git a/accel-pptpd/radius/auth.c b/accel-pptpd/radius/auth.c index 2415a05..e2d2478 100644 --- a/accel-pptpd/radius/auth.c +++ b/accel-pptpd/radius/auth.c @@ -19,7 +19,7 @@ static uint8_t* encrypt_password(const char *passwd, const char *secret, const u epasswd = malloc(chunk_cnt * 16); if (!epasswd) { - log_error("radius: out of memory\n"); + log_emerg("radius: out of memory\n"); return NULL; } @@ -137,7 +137,7 @@ int rad_auth_chap_md5(struct radius_pd_t *rpd, const char *username, va_list arg } if (!req->reply) - log_warn("radius:auth: no response\n"); + log_ppp_warn("radius:auth: no response\n"); else if (req->reply->code == CODE_ACCESS_ACCEPT) { rad_proc_attrs(req); r = PWDB_SUCCESS; diff --git a/accel-pptpd/radius/dict.c b/accel-pptpd/radius/dict.c index 4a0435a..0e96962 100644 --- a/accel-pptpd/radius/dict.c +++ b/accel-pptpd/radius/dict.c @@ -78,14 +78,14 @@ int rad_dict_load(const char *fname) buf = malloc(BUF_SIZE); if (!buf) { - log_error("radius: out of memory\n"); + log_emerg("radius: out of memory\n"); fclose(f); return -1; } dict = malloc(sizeof(*dict)); if (!dict) { - log_error("radius: out of memory\n"); + log_emerg("radius: out of memory\n"); fclose(f); free(buf); return -1; @@ -104,7 +104,7 @@ int rad_dict_load(const char *fname) if (!strcmp(buf, "ATTRIBUTE")) { attr = malloc(sizeof(*attr)); if (!attr) { - log_error("radius: out of memory\n"); + log_emerg("radius: out of memory\n"); goto out_err; } memset(attr, 0, sizeof(*attr)); @@ -138,7 +138,7 @@ int rad_dict_load(const char *fname) } val = malloc(sizeof(*val)); if (!val) { - log_error("radius: out of memory\n"); + log_emerg("radius: out of memory\n"); goto out_err; } memset(val, 0, sizeof(*val)); diff --git a/accel-pptpd/radius/dm_coa.c b/accel-pptpd/radius/dm_coa.c index c337b6a..784ad82 100644 --- a/accel-pptpd/radius/dm_coa.c +++ b/accel-pptpd/radius/dm_coa.c @@ -74,8 +74,8 @@ static int dm_coa_send_ack(int fd, struct rad_packet_t *req, struct sockaddr_in dm_coa_set_RA(reply, conf_dm_coa_secret); if (conf_verbose) { - log_debug("send "); - rad_packet_print(reply, log_debug); + log_ppp_debug("send "); + rad_packet_print(reply, log_ppp_debug); } rad_packet_send(reply, fd, addr); @@ -108,8 +108,8 @@ static int dm_coa_send_nak(int fd, struct rad_packet_t *req, struct sockaddr_in dm_coa_set_RA(reply, conf_dm_coa_secret); if (conf_verbose) { - log_debug("send "); - rad_packet_print(reply, log_debug); + log_ppp_debug("send "); + rad_packet_print(reply, log_ppp_debug); } rad_packet_send(reply, fd, addr); @@ -122,6 +122,11 @@ static int dm_coa_send_nak(int fd, struct rad_packet_t *req, struct sockaddr_in static void disconnect_request(struct radius_pd_t *rpd) { + if (conf_verbose) { + log_ppp_debug("recv "); + rad_packet_print(rpd->dm_coa_req, log_ppp_debug); + } + dm_coa_send_ack(serv.hnd.fd, rpd->dm_coa_req, &rpd->dm_coa_addr); rad_packet_free(rpd->dm_coa_req); @@ -132,6 +137,10 @@ static void disconnect_request(struct radius_pd_t *rpd) static void coa_request(struct radius_pd_t *rpd) { + if (conf_verbose) { + log_ppp_debug("recv "); + rad_packet_print(rpd->dm_coa_req, log_ppp_debug); + } /// TODO: CoA handling rad_packet_free(rpd->dm_coa_req); @@ -207,6 +216,7 @@ static void dm_coa_close(struct triton_context_t *ctx) static struct dm_coa_serv_t serv = { .ctx.close = dm_coa_close, + .ctx.before_switch = log_switch, .hnd.read = dm_coa_read, }; @@ -237,7 +247,7 @@ static void __init init(void) return; } - triton_context_register(&serv.ctx); + triton_context_register(&serv.ctx, NULL); triton_md_register_handler(&serv.ctx, &serv.hnd); triton_md_enable_handler(&serv.hnd, MD_MODE_READ); } diff --git a/accel-pptpd/radius/packet.c b/accel-pptpd/radius/packet.c index dcc1053..7d418d7 100644 --- a/accel-pptpd/radius/packet.c +++ b/accel-pptpd/radius/packet.c @@ -16,7 +16,7 @@ struct rad_packet_t *rad_packet_alloc(int code) pack = malloc(sizeof(*pack)); if (!pack) { - log_error("radius:packet: out of memory\n"); + log_emerg("radius:packet: out of memory\n"); return NULL; } @@ -48,7 +48,7 @@ int rad_packet_build(struct rad_packet_t *pack, uint8_t *RA) ptr = malloc(pack->len); if (!ptr) { - log_error("radius:packet: out of memory\n"); + log_emerg("radius:packet: out of memory\n"); return -1; } @@ -76,7 +76,7 @@ int rad_packet_build(struct rad_packet_t *pack, uint8_t *RA) *(uint32_t*)ptr = htonl(attr->val.date); break; default: - log_error("radius:packet:BUG: unknown attribute type\n"); + log_emerg("radius:packet:BUG: unknown attribute type\n"); abort(); } ptr += attr->len; @@ -101,7 +101,7 @@ struct rad_packet_t *rad_packet_recv(int fd, struct sockaddr_in *addr) pack->buf = malloc(REQ_LENGTH_MAX); if (!pack->buf) { - log_error("radius:packet: out of memory\n"); + log_emerg("radius:packet: out of memory\n"); goto out_err; } @@ -113,14 +113,14 @@ struct rad_packet_t *rad_packet_recv(int fd, struct sockaddr_in *addr) if (n < 0) { if (errno == EINTR) continue; - log_error("radius:packet:read: %s\n", strerror(errno)); + log_ppp_error("radius:packet:read: %s\n", strerror(errno)); goto out_err; } break; } if (n < 20) { - log_warn("radius:packet: short packed received (%i)\n", n); + log_ppp_warn("radius:packet: short packed received (%i)\n", n); goto out_err; } @@ -131,7 +131,7 @@ struct rad_packet_t *rad_packet_recv(int fd, struct sockaddr_in *addr) pack->len = ntohs(*(uint16_t*)ptr); ptr += 2; if (pack->len > n) { - log_warn("radius:packet: short packet received %i, expected %i\n", pack->len, n); + log_ppp_warn("radius:packet: short packet received %i, expected %i\n", pack->len, n); goto out_err; } @@ -142,18 +142,18 @@ struct rad_packet_t *rad_packet_recv(int fd, struct sockaddr_in *addr) id = *ptr; ptr++; len = *ptr - 2; ptr++; if (len < 0) { - log_warn("radius:packet short attribute len received\n"); + log_ppp_warn("radius:packet short attribute len received\n"); goto out_err; } if (2 + len > n) { - log_warn("radius:packet: too long attribute received (%i, %i)\n", id, len); + log_ppp_warn("radius:packet: too long attribute received (%i, %i)\n", id, len); goto out_err; } da = rad_dict_find_attr_id(id); if (da) { attr = malloc(sizeof(*attr)); if (!attr) { - log_error("radius:packet: out of memory\n"); + log_emerg("radius:packet: out of memory\n"); goto out_err; } attr->attr = da; @@ -162,7 +162,7 @@ struct rad_packet_t *rad_packet_recv(int fd, struct sockaddr_in *addr) case ATTR_TYPE_STRING: attr->val.string = malloc(len+1); if (!attr->val.string) { - log_error("radius:packet: out of memory\n"); + log_emerg("radius:packet: out of memory\n"); free(attr); goto out_err; } @@ -172,7 +172,7 @@ struct rad_packet_t *rad_packet_recv(int fd, struct sockaddr_in *addr) case ATTR_TYPE_OCTETS: attr->val.octets = malloc(len); if (!attr->val.octets) { - log_error("radius:packet: out of memory\n"); + log_emerg("radius:packet: out of memory\n"); free(attr); goto out_err; } @@ -188,7 +188,7 @@ struct rad_packet_t *rad_packet_recv(int fd, struct sockaddr_in *addr) } list_add_tail(&attr->entry, &pack->attrs); } else - log_warn("radius:packet: unknown attribute received (%i)\n", id); + log_ppp_warn("radius:packet: unknown attribute received (%i)\n", id); ptr += len; n -= 2 + len; } @@ -340,7 +340,7 @@ int rad_packet_add_octets(struct rad_packet_t *pack, const char *name, uint8_t * ra = malloc(sizeof(*ra)); if (!ra) { - log_error("radius: out of memory\n"); + log_emerg("radius: out of memory\n"); return -1; } @@ -348,7 +348,7 @@ int rad_packet_add_octets(struct rad_packet_t *pack, const char *name, uint8_t * ra->len = len; ra->val.octets = malloc(len); if (!ra->val.octets) { - log_error("radius: out of memory\n"); + log_emerg("radius: out of memory\n"); free(ra); return -1; } @@ -372,7 +372,7 @@ int rad_packet_add_str(struct rad_packet_t *pack, const char *name, const char * ra = malloc(sizeof(*ra)); if (!ra) { - log_error("radius: out of memory\n"); + log_emerg("radius: out of memory\n"); return -1; } @@ -380,7 +380,7 @@ int rad_packet_add_str(struct rad_packet_t *pack, const char *name, const char * ra->len = len; ra->val.string = malloc(len+1); if (!ra->val.string) { - log_error("radius: out of memory\n"); + log_emerg("radius: out of memory\n"); free(ra); return -1; } @@ -406,7 +406,7 @@ int rad_packet_change_str(struct rad_packet_t *pack, const char *name, const cha ra->val.string = realloc(ra->val.string, len + 1); if (!ra->val.string) { - log_error("radius: out of memory\n"); + log_emerg("radius: out of memory\n"); return -1; } @@ -491,10 +491,10 @@ int rad_packet_send(struct rad_packet_t *pack, int fd, struct sockaddr_in *addr) if (n < 0) { if (errno == EINTR) continue; - log_error("radius:write: %s\n", strerror(errno)); + log_ppp_error("radius:write: %s\n", strerror(errno)); return -1; } else if (n != pack->len) { - log_error("radius:write: short write %i, excpected %i\n", n, pack->len); + log_ppp_error("radius:write: short write %i, excpected %i\n", n, pack->len); return -1; } break; diff --git a/accel-pptpd/radius/radius.c b/accel-pptpd/radius/radius.c index 47a9aea..0e9d4b1 100644 --- a/accel-pptpd/radius/radius.c +++ b/accel-pptpd/radius/radius.c @@ -46,7 +46,7 @@ void rad_proc_attrs(struct rad_req_t *req) list_for_each_entry(attr, &req->reply->attrs, entry) { if (!strcmp(attr->attr->name, "Framed-IP-Address")) { if (!conf_gw_ip_address) - log_warn("radius: gw-ip-address not specified, cann't assign IP address...\n"); + log_ppp_warn("radius: gw-ip-address not specified, cann't assign IP address...\n"); else { req->rpd->ipaddr.owner = &ipdb; req->rpd->ipaddr.peer_addr = attr->val.ipaddr; @@ -105,7 +105,7 @@ static void ppp_starting(struct ppp_t *ppp) struct radius_pd_t *pd = malloc(sizeof(*pd)); memset(pd, 0, sizeof(*pd)); - pd->pd.key = pd_key; + pd->pd.key = &pd_key; pd->ppp = ppp; pthread_mutex_init(&pd->lock, NULL); list_add_tail(&pd->pd.entry, &ppp->pd_list); @@ -151,12 +151,12 @@ struct radius_pd_t *find_pd(struct ppp_t *ppp) struct radius_pd_t *rpd; list_for_each_entry(pd, &ppp->pd_list, entry) { - if (pd->key == pd_key) { + if (pd->key == &pd_key) { rpd = container_of(pd, typeof(*rpd), pd); return rpd; } } - log_error("radius:BUG: rpd not found\n"); + log_emerg("radius:BUG: rpd not found\n"); abort(); } diff --git a/accel-pptpd/radius/req.c b/accel-pptpd/radius/req.c index 40397a8..4a7ac43 100644 --- a/accel-pptpd/radius/req.c +++ b/accel-pptpd/radius/req.c @@ -1,4 +1,5 @@ #include <stdlib.h> +#include <stdio.h> #include <string.h> #include <errno.h> #include <fcntl.h> @@ -25,6 +26,7 @@ struct rad_req_t *rad_req_alloc(struct radius_pd_t *rpd, int code, const char *u memset(req, 0, sizeof(*req)); req->rpd = rpd; req->hnd.fd = -1; + req->ctx.before_switch = log_switch; req->server_name = conf_auth_server; req->server_port = conf_auth_server_port; @@ -33,7 +35,7 @@ struct rad_req_t *rad_req_alloc(struct radius_pd_t *rpd, int code, const char *u if (read(urandom_fd, req->RA, 16) != 16) { if (errno == EINTR) continue; - log_error("radius:req:read urandom: %s\n", strerror(errno)); + log_ppp_error("radius:req:read urandom: %s\n", strerror(errno)); goto out_err; } break; @@ -106,7 +108,7 @@ static int make_socket(struct rad_req_t *req) req->hnd.fd = socket(PF_INET, SOCK_DGRAM, 0); if (req->hnd.fd < 0) { - log_error("radius:socket: %s\n", strerror(errno)); + log_ppp_error("radius:socket: %s\n", strerror(errno)); return -1; } @@ -116,7 +118,7 @@ static int make_socket(struct rad_req_t *req) if (conf_nas_ip_address) { addr.sin_addr.s_addr = inet_addr(conf_nas_ip_address); if (bind(req->hnd.fd, (struct sockaddr *) &addr, sizeof(addr))) { - log_error("radius:bind: %s\n", strerror(errno)); + log_ppp_error("radius:bind: %s\n", strerror(errno)); goto out_err; } } @@ -125,12 +127,12 @@ static int make_socket(struct rad_req_t *req) addr.sin_port = htons(req->server_port); if (connect(req->hnd.fd, (struct sockaddr *) &addr, sizeof(addr))) { - log_error("radius:connect: %s\n", strerror(errno)); + log_ppp_error("radius:connect: %s\n", strerror(errno)); goto out_err; } if (fcntl(req->hnd.fd, F_SETFL, O_NONBLOCK)) { - log_error("radius: failed to set nonblocking mode: %s\n", strerror(errno)); + log_ppp_error("radius: failed to set nonblocking mode: %s\n", strerror(errno)); goto out_err; } @@ -151,8 +153,8 @@ int rad_req_send(struct rad_req_t *req) goto out_err; if (conf_verbose) { - log_debug("send "); - rad_packet_print(req->pack, log_debug); + log_ppp_debug("send "); + rad_packet_print(req->pack, log_ppp_debug); } rad_packet_send(req->pack, req->hnd.fd, NULL); @@ -193,7 +195,7 @@ int rad_req_wait(struct rad_req_t *req, int timeout) req->hnd.read = rad_req_read; req->timeout.expire = rad_req_timeout; - triton_context_register(&req->ctx); + triton_context_register(&req->ctx, req->rpd->ppp); triton_md_register_handler(&req->ctx, &req->hnd); if (triton_md_enable_handler(&req->hnd, MD_MODE_READ)) return -1; @@ -205,8 +207,8 @@ int rad_req_wait(struct rad_req_t *req, int timeout) triton_context_schedule(req->rpd->ppp->ctrl->ctx); if (conf_verbose && req->reply) { - log_debug("recv "); - rad_packet_print(req->reply, log_debug); + log_ppp_debug("recv "); + rad_packet_print(req->reply, log_ppp_debug); } return 0; } |