summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitry Kozlov <xeb@mail.ru>2011-01-26 22:47:10 +0300
committerDmitry Kozlov <xeb@mail.ru>2011-01-26 22:47:10 +0300
commit419de8f6910e4fd5d442068ad5ae41b530169470 (patch)
treef28b69928983f8c772f40e873ce571379e9fa546
parentb997d19f3b6e3087bffb072dd326c4b5311143b5 (diff)
downloadaccel-ppp-419de8f6910e4fd5d442068ad5ae41b530169470.tar.gz
accel-ppp-419de8f6910e4fd5d442068ad5ae41b530169470.zip
dynamicaly check if radius module loaded (so not more require to rebuild project without RADIUS to switch to chap-secrets)
-rw-r--r--accel-pppd/ctrl/pppoe/pppoe.c2
-rw-r--r--accel-pppd/extra/pppd_compat.c6
-rw-r--r--accel-pppd/extra/shaper_tbf.c46
-rw-r--r--accel-pppd/radius/radius.c9
-rw-r--r--accel-pppd/radius/radius_p.h3
-rw-r--r--accel-pppd/triton/loader.c48
-rw-r--r--accel-pppd/triton/triton.h2
7 files changed, 90 insertions, 26 deletions
diff --git a/accel-pppd/ctrl/pppoe/pppoe.c b/accel-pppd/ctrl/pppoe/pppoe.c
index d718beda..c7612e25 100644
--- a/accel-pppd/ctrl/pppoe/pppoe.c
+++ b/accel-pppd/ctrl/pppoe/pppoe.c
@@ -311,7 +311,7 @@ static void connect_channel(struct pppoe_conn_t *conn)
goto out_err_close;
#ifdef RADIUS
- if (conn->tr101) {
+ if (conn->tr101 && triton_module_loaded("radius")) {
conn->radius.send_access_request = pppoe_rad_send_access_request;
conn->radius.send_accounting_request = pppoe_rad_send_accounting_request;
rad_register_plugin(&conn->ppp, &conn->radius);
diff --git a/accel-pppd/extra/pppd_compat.c b/accel-pppd/extra/pppd_compat.c
index 66f54535..5fa9bebf 100644
--- a/accel-pppd/extra/pppd_compat.c
+++ b/accel-pppd/extra/pppd_compat.c
@@ -531,7 +531,9 @@ static void __init init(void)
triton_event_register_handler(EV_PPP_FINISHING, (triton_event_func)ev_ppp_finishing);
triton_event_register_handler(EV_PPP_FINISHED, (triton_event_func)ev_ppp_finished);
#ifdef RADIUS
- triton_event_register_handler(EV_RADIUS_ACCESS_ACCEPT, (triton_event_func)ev_radius_access_accept);
- triton_event_register_handler(EV_RADIUS_COA, (triton_event_func)ev_radius_coa);
+ if (triton_module_loaded("radius")) {
+ triton_event_register_handler(EV_RADIUS_ACCESS_ACCEPT, (triton_event_func)ev_radius_access_accept);
+ triton_event_register_handler(EV_RADIUS_COA, (triton_event_func)ev_radius_coa);
+ }
#endif
}
diff --git a/accel-pppd/extra/shaper_tbf.c b/accel-pppd/extra/shaper_tbf.c
index ddd7e350..cc0ff22d 100644
--- a/accel-pppd/extra/shaper_tbf.c
+++ b/accel-pppd/extra/shaper_tbf.c
@@ -1161,27 +1161,29 @@ static void load_config(void)
const char *opt;
#ifdef RADIUS
- opt = conf_get_opt("tbf", "vendor");
- if (opt)
- conf_vendor = parse_vendor_opt(opt);
-
- opt = conf_get_opt("tbf", "attr");
- if (opt) {
- conf_attr_down = parse_attr_opt(opt);
- conf_attr_up = parse_attr_opt(opt);
- }
+ if (triton_module_loaded("radius")) {
+ opt = conf_get_opt("tbf", "vendor");
+ if (opt)
+ conf_vendor = parse_vendor_opt(opt);
+
+ opt = conf_get_opt("tbf", "attr");
+ if (opt) {
+ conf_attr_down = parse_attr_opt(opt);
+ conf_attr_up = parse_attr_opt(opt);
+ }
- opt = conf_get_opt("tbf", "attr-down");
- if (opt)
- conf_attr_down = parse_attr_opt(opt);
-
- opt = conf_get_opt("tbf", "attr-up");
- if (opt)
- conf_attr_up = parse_attr_opt(opt);
+ opt = conf_get_opt("tbf", "attr-down");
+ if (opt)
+ conf_attr_down = parse_attr_opt(opt);
+
+ opt = conf_get_opt("tbf", "attr-up");
+ if (opt)
+ conf_attr_up = parse_attr_opt(opt);
- if (conf_attr_up <= 0 || conf_attr_down <= 0) {
- log_emerg("tbf: incorrect attribute(s), tbf disabled...\n");
- return;
+ if (conf_attr_up <= 0 || conf_attr_down <= 0) {
+ log_emerg("tbf: incorrect attribute(s), tbf disabled...\n");
+ return;
+ }
}
#endif
@@ -1260,8 +1262,10 @@ static void __init init(void)
load_config();
#ifdef RADIUS
- triton_event_register_handler(EV_RADIUS_ACCESS_ACCEPT, (triton_event_func)ev_radius_access_accept);
- triton_event_register_handler(EV_RADIUS_COA, (triton_event_func)ev_radius_coa);
+ if (triton_module_loaded("radius")) {
+ triton_event_register_handler(EV_RADIUS_ACCESS_ACCEPT, (triton_event_func)ev_radius_access_accept);
+ triton_event_register_handler(EV_RADIUS_COA, (triton_event_func)ev_radius_coa);
+ }
#endif
triton_event_register_handler(EV_CTRL_FINISHED, (triton_event_func)ev_ctrl_finished);
triton_event_register_handler(EV_SHAPER, (triton_event_func)ev_shaper);
diff --git a/accel-pppd/radius/radius.c b/accel-pppd/radius/radius.c
index 04de1b79..f371598a 100644
--- a/accel-pppd/radius/radius.c
+++ b/accel-pppd/radius/radius.c
@@ -146,6 +146,9 @@ static int check(struct pwdb_t *pwdb, struct ppp_t *ppp, const char *username, i
va_end(args);
+ if (r == PWDB_SUCCESS)
+ rpd->authenticated = 1;
+
return r;
}
@@ -192,6 +195,9 @@ static void ppp_starting(struct ppp_t *ppp)
static void ppp_acct_start(struct ppp_t *ppp)
{
struct radius_pd_t *rpd = find_pd(ppp);
+
+ if (!rpd->authenticated)
+ return;
if (rad_acct_start(rpd)) {
ppp_terminate(rpd->ppp, TERM_NAS_ERROR, 0);
@@ -207,6 +213,9 @@ static void ppp_finishing(struct ppp_t *ppp)
{
struct radius_pd_t *rpd = find_pd(ppp);
+ if (!rpd->authenticated)
+ return;
+
rad_acct_stop(rpd);
}
static void ppp_finished(struct ppp_t *ppp)
diff --git a/accel-pppd/radius/radius_p.h b/accel-pppd/radius/radius_p.h
index 71c1a637..e539dd8b 100644
--- a/accel-pppd/radius/radius_p.h
+++ b/accel-pppd/radius/radius_p.h
@@ -15,6 +15,7 @@ struct radius_pd_t
struct ppp_pd_t pd;
struct ppp_t *ppp;
pthread_mutex_t lock;
+ int authenticated:1;
struct rad_req_t *auth_req;
struct rad_req_t *acct_req;
@@ -37,7 +38,7 @@ struct radius_pd_t
int attr_class_len;
uint8_t *attr_state;
int attr_state_len;
- int termination_action;
+ int termination_action;
struct list_head plugin_list;
};
diff --git a/accel-pppd/triton/loader.c b/accel-pppd/triton/loader.c
index 2a2a2e2f..e2faeb2e 100644
--- a/accel-pppd/triton/loader.c
+++ b/accel-pppd/triton/loader.c
@@ -10,12 +10,24 @@
#include "memdebug.h"
+struct module_t
+{
+ struct list_head entry;
+ char *name;
+ void *handle;
+};
+
+static LIST_HEAD(modules);
+
int load_modules(const char *name)
{
struct conf_sect_t *sect;
struct conf_option_t *opt;
char *fname;
char *path = MODULE_PATH;
+ char *ptr1, *ptr2;
+ struct module_t *m;
+ void *h;
sect = conf_get_section(name);
if (!sect) {
@@ -48,11 +60,32 @@ int load_modules(const char *name)
}
}
- if (!dlopen(fname, RTLD_LAZY | RTLD_GLOBAL)) {
+ h = dlopen(fname, RTLD_LAZY | RTLD_GLOBAL);
+ if (!h) {
triton_log_error("loader: failed to load '%s': %s\n", opt->name, dlerror());
_free(fname);
return -1;
}
+
+ ptr1 = fname;
+ while (1) {
+ ptr2 = strchr(ptr1, '/');
+ if (!ptr2)
+ break;
+ ptr1 = ptr2 + 1;
+ }
+
+ if (!strncmp(ptr1, "lib", 3))
+ ptr1 += 3;
+
+ ptr2 = strstr(ptr1, ".so\x0");
+ if (ptr2)
+ *ptr2 = 0;
+
+ m = _malloc(sizeof(*m));
+ m->name = _strdup(ptr1);
+ m->handle = h;
+ list_add_tail(&m->entry, &modules);
}
_free(fname);
@@ -60,3 +93,16 @@ int load_modules(const char *name)
return 0;
}
+int __export triton_module_loaded(const char *name)
+{
+ struct module_t *m;
+
+ list_for_each_entry(m, &modules, entry) {
+ if (strcmp(m->name, name))
+ continue;
+ return 1;
+ }
+
+ return 0;
+}
+
diff --git a/accel-pppd/triton/triton.h b/accel-pppd/triton/triton.h
index 6866d523..98ef1113 100644
--- a/accel-pppd/triton/triton.h
+++ b/accel-pppd/triton/triton.h
@@ -104,6 +104,8 @@ void triton_conf_reload(void (*notify)(int));
void triton_collect_cpu_usage(void);
void triton_stop_collect_cpu_usage(void);
+int triton_module_loaded(const char *name);
+
#define TRITON_OK 0
#define TRITON_ERR_NOCOMP -1