summaryrefslogtreecommitdiff
path: root/accel-pptpd/radius/radius.c
diff options
context:
space:
mode:
Diffstat (limited to 'accel-pptpd/radius/radius.c')
-rw-r--r--accel-pptpd/radius/radius.c105
1 files changed, 93 insertions, 12 deletions
diff --git a/accel-pptpd/radius/radius.c b/accel-pptpd/radius/radius.c
index 10fef65f..4d020d5b 100644
--- a/accel-pptpd/radius/radius.c
+++ b/accel-pptpd/radius/radius.c
@@ -7,23 +7,105 @@
#include "pwdb.h"
#include "radius.h"
-struct radius_pd_t
+static struct ppp_notified_t notified;
+
+static int check_pap(struct radius_pd_t *rpd, const char *username, va_list args)
{
- struct ppp_pd_t pd;
- struct ppp_t *ppp;
-};
+ struct rad_req_t *req;
+ int i, r = PWDB_DENIED;
+ int id = va_arg(args, int);
+ const char *passwd = va_arg(args, const char *);
-static struct ppp_notified_t notified;
+ req = rad_req_alloc(rpd, CODE_ACCESS_REQUEST);
+ if (!req)
+ return PWDB_DENIED;
+
+ if (rad_req_add_str(req, "User-Password", passwd, strlen(passwd)))
+ goto out;
+
+ for(i = 0; i < max_try; i++) {
+ if (rad_req_send(req))
+ goto out;
+
+ if (rad_req_wait(req, timeout))
+ goto out;
+
+ if (req->answer)
+ break;
+ }
+
+out:
+ rad_req_free(req);
+
+ return r;
+}
+
+static int check_chap_md5(struct radius_pd_t *rpd, const char *username, va_list args)
+{
+ int id = va_arg(args, int);
+ const uint8_t *challenge = va_arg(args, const uint8_t *);
+}
-int cleartext_check(struct pwdb_t *pwdb, struct ppp_t *ppp, const char *username, const char *password)
+static int check_mschap_v1(struct radius_pd_t *rpd, const char *username, va_list args)
{
- return PWDB_NO_IMPL;
+ int id = va_arg(args, int);
+ const uint8_t *challenge = va_arg(args, const uint8_t *);
+ const uint8_t *lm_response = va_arg(args, const uint8_t *);
+ const uint8_t *nt_response = va_arg(args, const uint8_t *);
+ int flags = va_arg(args, int);
}
-int encrypted_check(struct pwdb_t *pwdb, struct ppp_t *ppp, const char *username, int type, va_list args)
+
+static int check_mschap_v2(struct radius_pd_t *rpd, const char *username, va_list args)
{
- return PWDB_NO_IMPL;
+ int id = va_arg(args, int);
+ const uint8_t *challenge = va_arg(args, const uint8_t *);
+ const uint8_t *peer_challenge = va_arg(args, const uint8_t *);
+ const uint8_t *response = va_arg(args, const uint8_t *);
+ int flags = va_arg(args, int);
+ uint8_t *authenticator = va_arg(args, uint8_t *);
}
+static int check(struct pwdb_t *pwdb, struct ppp_t *ppp, const char *username, int type, va_list _args)
+{
+ int r = PWDB_NO_IMPL;
+ va_list args;
+ int chap_type;
+ struct ppp_pd_t *pd;
+ struct radius_pd_t *rpd = NULL;
+
+ list_for_each_entry(pd, &ppp->pd_list, entry) {
+ if (pd->key == &notified) {
+ rpd = container_of(pd, typeof(*rpd), pd);
+ break;
+ }
+ }
+
+ va_copy(args, _args);
+
+ switch(type) {
+ case PPP_PAP:
+ r = check_pap(rpd, username, args);
+ break;
+ case PPP_CHAP:
+ chap_type = va_arg(args, int);
+ switch(chap_type) {
+ case 0x05:
+ r = check_chap_md5(rpd, username, args);
+ break;
+ case 0x80:
+ r = check_mschap_v1(rpd, username, args);
+ break;
+ case 0x81:
+ r = check_mschap_v2(rpd, username, args);
+ break;
+ }
+ break;
+ }
+
+ va_end(args);
+
+ return r;
+}
static void ppp_started(struct ppp_notified_t *n, struct ppp_t *ppp)
{
@@ -50,9 +132,8 @@ static void ppp_finished(struct ppp_notified_t *n, struct ppp_t *ppp)
}
}
-struct pwdb_t pwdb = {
- .cleartext_check = cleartext_check,
- .encrypted_check = encrypted_check,
+static struct pwdb_t pwdb = {
+ .check = check,
};
static struct ppp_notified_t notified = {