summaryrefslogtreecommitdiff
path: root/accel-pppd/ppp
diff options
context:
space:
mode:
authorKozlov Dmitry <dima@server>2011-04-20 15:06:28 +0400
committerKozlov Dmitry <dima@server>2011-04-20 15:06:28 +0400
commitbbbe1fd4f5c91210a4246225aff7728fa58384f3 (patch)
tree82d89e181025b1d593a32202904c03f0312a4e4d /accel-pppd/ppp
parentd4f6b13bcfb5c6245d39f5a71db199bac5a0a26f (diff)
downloadaccel-ppp-bbbe1fd4f5c91210a4246225aff7728fa58384f3.tar.gz
accel-ppp-bbbe1fd4f5c91210a4246225aff7728fa58384f3.zip
ppp: introduced new option 'single-session' to control single session per user
Diffstat (limited to 'accel-pppd/ppp')
-rw-r--r--accel-pppd/ppp/ppp.c12
-rw-r--r--accel-pppd/ppp/ppp.h1
-rw-r--r--accel-pppd/ppp/ppp_auth.c32
-rw-r--r--accel-pppd/ppp/ppp_auth.h2
4 files changed, 43 insertions, 4 deletions
diff --git a/accel-pppd/ppp/ppp.c b/accel-pppd/ppp/ppp.c
index a044d9a..5a4006c 100644
--- a/accel-pppd/ppp/ppp.c
+++ b/accel-pppd/ppp/ppp.c
@@ -25,7 +25,8 @@
#include "memdebug.h"
int __export conf_ppp_verbose;
-static int conf_sid_ucase;
+int conf_sid_ucase;
+int conf_single_session = -1;
pthread_rwlock_t __export ppp_lock = PTHREAD_RWLOCK_INITIALIZER;
__export LIST_HEAD(ppp_list);
@@ -640,6 +641,15 @@ static void load_config(void)
else if (strcmp(opt, "lower"))
log_emerg("ppp: sid-case: invalid format\n");
}
+
+ opt = conf_get_opt("ppp", "single-session");
+ if (opt) {
+ if (!strcmp(opt, "deny"))
+ conf_single_session = 0;
+ else if (!strcmp(opt, "replace"))
+ conf_single_session = 1;
+ } else
+ conf_single_session = -1;
}
static void __init init(void)
diff --git a/accel-pppd/ppp/ppp.h b/accel-pppd/ppp/ppp.h
index 8556b2c..9d2409e 100644
--- a/accel-pppd/ppp/ppp.h
+++ b/accel-pppd/ppp/ppp.h
@@ -178,6 +178,7 @@ extern int ppp_shutdown;
void ppp_shutdown_soft(void);
extern int conf_ppp_verbose;
+extern int conf_single_session;
extern pthread_rwlock_t ppp_lock;
extern struct list_head ppp_list;
diff --git a/accel-pppd/ppp/ppp_auth.c b/accel-pppd/ppp/ppp_auth.c
index 32413c6..e58b9a5 100644
--- a/accel-pppd/ppp/ppp_auth.c
+++ b/accel-pppd/ppp/ppp_auth.c
@@ -299,14 +299,42 @@ static void auth_layer_free(struct ppp_layer_data_t *ld)
_free(ad);
}
-void __export ppp_auth_successed(struct ppp_t *ppp, char *username)
+static void ppp_terminate_sec(struct ppp_t *ppp)
{
+ ppp_terminate(ppp, TERM_NAS_REQUEST, 0);
+}
+
+int __export ppp_auth_successed(struct ppp_t *ppp, char *username)
+{
+ struct ppp_t *p;
struct auth_layer_data_t *ad = container_of(ppp_find_layer_data(ppp, &auth_layer), typeof(*ad), ld);
- log_ppp_debug("auth_layer_started\n");
+
+ pthread_rwlock_rdlock(&ppp_lock);
+ list_for_each_entry(p, &ppp_list, entry) {
+ if (p->username && !strcmp(p->username, username)) {
+ if (conf_single_session == 0) {
+ pthread_rwlock_unlock(&ppp_lock);
+ log_ppp_info1("%s: second session denied\n", username);
+ return -1;
+ } else {
+ if (conf_single_session == 1)
+ triton_context_call(p->ctrl->ctx, (triton_event_func)ppp_terminate_sec, p);
+ break;
+ }
+ }
+ }
+ pthread_rwlock_unlock(&ppp_lock);
+
+ pthread_rwlock_wrlock(&ppp_lock);
ppp->username = username;
+ pthread_rwlock_unlock(&ppp_lock);
+
+ log_ppp_debug("auth_layer_started\n");
ppp_layer_started(ppp, &ad->ld);
log_ppp_info1("%s: authentication successed\n", username);
triton_event_fire(EV_PPP_AUTHORIZED, ppp);
+
+ return 0;
}
void __export ppp_auth_failed(struct ppp_t *ppp, const char *username)
diff --git a/accel-pppd/ppp/ppp_auth.h b/accel-pppd/ppp/ppp_auth.h
index 87cc742..c84f5f9 100644
--- a/accel-pppd/ppp/ppp_auth.h
+++ b/accel-pppd/ppp/ppp_auth.h
@@ -29,7 +29,7 @@ struct ppp_auth_handler_t
int ppp_auth_register_handler(struct ppp_auth_handler_t*);
-void ppp_auth_successed(struct ppp_t *ppp, char *username);
+int ppp_auth_successed(struct ppp_t *ppp, char *username);
void ppp_auth_failed(struct ppp_t *ppp, const char *username);
int ppp_auth_restart(struct ppp_t *ppp);