From 4bec34636fc79f41b73da8751beebca210c77470 Mon Sep 17 00:00:00 2001
From: Kozlov Dmitry <dima@server>
Date: Tue, 9 Nov 2010 13:40:10 +0300
Subject: auth: any login support for PAP/CHAP/MSCHAP-v1

---
 accel-pptpd/auth/auth_chap_md5.c  | 12 ++++++++++++
 accel-pptpd/auth/auth_mschap_v1.c | 14 +++++++++++++-
 accel-pptpd/auth/auth_pap.c       | 13 +++++++++++++
 3 files changed, 38 insertions(+), 1 deletion(-)

diff --git a/accel-pptpd/auth/auth_chap_md5.c b/accel-pptpd/auth/auth_chap_md5.c
index 89124105..634fba23 100644
--- a/accel-pptpd/auth/auth_chap_md5.c
+++ b/accel-pptpd/auth/auth_chap_md5.c
@@ -34,6 +34,7 @@
 static int conf_timeout = 5;
 static int conf_interval = 0;
 static int conf_max_failure = 3;
+static int conf_any_login = 0;
 
 static int urandom_fd;
 
@@ -284,6 +285,13 @@ static void chap_recv_response(struct chap_auth_data_t *ad, struct chap_hdr_t *h
 
 	name = _strndup(msg->name,ntohs(msg->hdr.len) - sizeof(*msg) + 2);
 
+	if (conf_any_login) {
+		chap_send_success(ad);
+		ad->started = 1;
+		ppp_auth_successed(ad->ppp, name);
+		return;
+	}
+
 	r = pwdb_check(ad->ppp, name, PPP_CHAP, CHAP_MD5, ad->id, ad->val, VALUE_SIZE, msg->val);
 
 	if (r == PWDB_NO_IMPL) {
@@ -402,6 +410,10 @@ static void __init auth_chap_md5_init()
 	if (opt && atoi(opt) > 0)
 		conf_max_failure = atoi(opt);
 
+	opt = conf_get_opt("auth", "any-login");
+	if (opt && atoi(opt) > 0)
+		conf_any_login = 1;
+
 	urandom_fd=open("/dev/urandom", O_RDONLY);
 
 	if (urandom_fd < 0) {
diff --git a/accel-pptpd/auth/auth_mschap_v1.c b/accel-pptpd/auth/auth_mschap_v1.c
index c2fc4321..280a6727 100644
--- a/accel-pptpd/auth/auth_mschap_v1.c
+++ b/accel-pptpd/auth/auth_mschap_v1.c
@@ -39,6 +39,7 @@
 static int conf_timeout = 5;
 static int conf_interval = 0;
 static int conf_max_failure = 3;
+static int conf_any_login = 0;
 
 static int urandom_fd;
 
@@ -313,7 +314,14 @@ static void chap_recv_response(struct chap_auth_data_t *ad, struct chap_hdr_t *h
 			ppp_auth_failed(ad->ppp);
 		return;
 	}
-	
+
+	if (conf_any_login) {
+		chap_send_success(ad);
+		ad->started = 1;
+		ppp_auth_successed(ad->ppp, name);
+		return;
+	}
+
 	r = pwdb_check(ad->ppp, name, PPP_CHAP, MSCHAP_V1, ad->id, ad->val, VALUE_SIZE, msg->lm_hash, msg->nt_hash, msg->flags);
 	if (r == PWDB_NO_IMPL)
 		if (chap_check_response(ad, msg, name))
@@ -494,6 +502,10 @@ static void __init auth_mschap_v1_init()
 	if (opt && atoi(opt) > 0)
 		conf_max_failure = atoi(opt);
 
+	opt = conf_get_opt("auth", "any-login");
+	if (opt && atoi(opt) > 0)
+		conf_any_login = 1;
+
 	urandom_fd = open("/dev/urandom", O_RDONLY);
 	if (urandom_fd < 0) {
 		log_emerg("mschap-v1: failed to open /dev/urandom: %s\n", strerror(errno));
diff --git a/accel-pptpd/auth/auth_pap.c b/accel-pptpd/auth/auth_pap.c
index 96640a1a..27b4dd8a 100644
--- a/accel-pptpd/auth/auth_pap.c
+++ b/accel-pptpd/auth/auth_pap.c
@@ -21,6 +21,7 @@
 #define PAP_NAK 3
 
 static int conf_timeout = 5;
+static int conf_any_login = 0;
 
 static struct auth_data_t* auth_data_init(struct ppp_t *ppp);
 static void auth_data_free(struct ppp_t*, struct auth_data_t*);
@@ -195,6 +196,14 @@ static int pap_recv_req(struct pap_auth_data_t *p, struct pap_hdr_t *hdr)
 	}
 
 	peer_id = _strndup((const char*)peer_id, peer_id_len);
+	
+	if (conf_any_login) {
+		pap_send_ack(p, hdr->id);
+		p->started = 1;
+		ppp_auth_successed(p->ppp, peer_id);
+		return 0;
+	}
+
 	passwd = _strndup((const char*)ptr, passwd_len);
 
 	r = pwdb_check(p->ppp, peer_id, PPP_PAP, passwd);
@@ -255,6 +264,10 @@ static void __init auth_pap_init()
 	if (opt && atoi(opt) > 0)
 		conf_timeout = atoi(opt);
 
+	opt = conf_get_opt("auth", "any-login");
+	if (opt && atoi(opt) > 0)
+		conf_any_login = 1;
+
 	ppp_auth_register_handler(&pap);
 }
 
-- 
cgit v1.2.3