summaryrefslogtreecommitdiff
path: root/accel-pptpd
diff options
context:
space:
mode:
authorDmitry Kozlov <xeb@mail.ru>2010-09-06 22:43:20 +0400
committerDmitry Kozlov <xeb@mail.ru>2010-09-06 22:43:20 +0400
commitec759f72fcf7d517fdfe8d043c75d0218363bc78 (patch)
tree0696c9977599bf0f20e016e5464e59a6c3fe980e /accel-pptpd
parent45243dd2f2be49cd91be1dc28932e6c9040db6a1 (diff)
downloadaccel-ppp-ec759f72fcf7d517fdfe8d043c75d0218363bc78.tar.gz
accel-ppp-ec759f72fcf7d517fdfe8d043c75d0218363bc78.zip
now compiles
Diffstat (limited to 'accel-pptpd')
-rw-r--r--accel-pptpd/radius/dict.c12
-rw-r--r--accel-pptpd/radius/packet.c32
-rw-r--r--accel-pptpd/radius/radius.c35
-rw-r--r--accel-pptpd/radius/radius.h17
-rw-r--r--accel-pptpd/radius/req.c63
-rw-r--r--accel-pptpd/triton/triton.h1
6 files changed, 101 insertions, 59 deletions
diff --git a/accel-pptpd/radius/dict.c b/accel-pptpd/radius/dict.c
index 992d7d40..00f67af7 100644
--- a/accel-pptpd/radius/dict.c
+++ b/accel-pptpd/radius/dict.c
@@ -50,9 +50,9 @@ static int split(char *buf, char **ptr)
return 0;
}
-struct dict_attr_t *find_attr(struct rad_dict_t *dict, const char *name)
+struct rad_dict_attr_t *find_attr(struct rad_dict_t *dict, const char *name)
{
- struct dict_attr_t *attr;
+ struct rad_dict_attr_t *attr;
list_for_each_entry(attr, &dict->items, entry)
if (!strcmp(attr->name, name))
@@ -67,8 +67,8 @@ int rad_dict_load(const char *fname)
FILE *f;
char *buf, *ptr[3], *endptr;
int n = 0;
- struct dict_attr_t *attr;
- struct dict_value_t *val;
+ struct rad_dict_attr_t *attr;
+ struct rad_dict_value_t *val;
f = fopen(fname, "r");
if (!f) {
@@ -180,8 +180,8 @@ out_err:
void rad_dict_free(struct rad_dict_t *dict)
{
- struct dict_attr_t *attr;
- struct dict_value_t *val;
+ struct rad_dict_attr_t *attr;
+ struct rad_dict_value_t *val;
while (!list_empty(&dict->items)) {
attr = list_entry(dict->items.next, typeof(*attr), entry);
diff --git a/accel-pptpd/radius/packet.c b/accel-pptpd/radius/packet.c
index a22a611e..f1b4ebea 100644
--- a/accel-pptpd/radius/packet.c
+++ b/accel-pptpd/radius/packet.c
@@ -2,7 +2,10 @@
#include <stdio.h>
#include <string.h>
#include <errno.h>
-#include <stdin.h>
+#include <stdio.h>
+#include <unistd.h>
+
+#include "log.h"
#include "radius.h"
@@ -21,9 +24,9 @@ int rad_packet_build(struct rad_packet_t *pack)
*ptr = pack->code; ptr++;
*ptr = pack->id; ptr++;
- *(uint16_t*)ptr = pack->len; pt r+= 2;
+ *(uint16_t*)ptr = pack->len; ptr+= 2;
while (1) {
- if (read(erandom_fd, ptr, 16) != 16) {
+ if (read(urandom_fd, ptr, 16) != 16) {
if (errno == EINTR)
continue;
log_error("radius:packet:read urandom: %s\n", strerror(errno));
@@ -34,14 +37,14 @@ int rad_packet_build(struct rad_packet_t *pack)
ptr+=16;
list_for_each_entry(attr, &pack->attrs, entry) {
- *ptr = attr->attr.id; ptr++;
+ *ptr = attr->attr->type; ptr++;
*ptr = attr->len; ptr++;
- switch(attr->attr.type) {
+ switch(attr->attr->type) {
case ATTR_TYPE_INTEGER:
*(uint32_t*)ptr = attr->val.integer;
break;
case ATTR_TYPE_STRING:
- memcpy(ptr, attr->val.string);
+ memcpy(ptr, attr->val.string, attr->len);
break;
case ATTR_TYPE_IPADDR:
*(in_addr_t*)ptr = attr->val.ipaddr;
@@ -57,6 +60,10 @@ int rad_packet_build(struct rad_packet_t *pack)
}
return 0;
+
+out_err:
+ free(ptr);
+ return -1;
}
struct rad_packet_t *rad_packet_recv(int fd)
@@ -76,7 +83,7 @@ struct rad_packet_t *rad_packet_recv(int fd)
memset(pack, 0, sizeof(*pack));
INIT_LIST_HEAD(&pack->attrs);
- pack->buf = malloc(REQ_MAX_LENGTH);
+ pack->buf = malloc(REQ_LENGTH_MAX);
if (!pack->buf) {
log_error("radius:packet: out of memory\n");
free(pack);
@@ -84,7 +91,7 @@ struct rad_packet_t *rad_packet_recv(int fd)
}
while (1) {
- n = read(fd, pack->buf, REQ_MAX_LENGTH);
+ n = read(fd, pack->buf, REQ_LENGTH_MAX);
if (n < 0) {
if (errno == EINTR)
continue;
@@ -120,7 +127,7 @@ struct rad_packet_t *rad_packet_recv(int fd)
log_error("radius:packet: too long attribute received (%i, %i)\n", type, len);
goto out_err;
}
- da = rad_dict_find_attr_type(n);
+ da = rad_dict_find_attr_type(type);
if (da) {
attr = malloc(sizeof(*attr));
if (!attr) {
@@ -128,7 +135,6 @@ struct rad_packet_t *rad_packet_recv(int fd)
goto out_err;
}
attr->attr = da;
- attr->type = type;
attr->len = len;
if (type == ATTR_TYPE_STRING) {
attr->val.string = malloc(len);
@@ -138,7 +144,7 @@ struct rad_packet_t *rad_packet_recv(int fd)
goto out_err;
}
} else
- memcpy(&attr->type.integer, ptr, 4);
+ memcpy(&attr->val.integer, ptr, 4);
list_add_tail(&attr->entry, &pack->attrs);
} else
log_warn("radius:packet: unknown attribute type received (%i)\n", type);
@@ -162,8 +168,8 @@ void rad_packet_free(struct rad_packet_t *pack)
while(!list_empty(&pack->attrs)) {
attr = list_entry(pack->attrs.next, typeof(*attr), entry);
- if (attr->attr.type == ATTR_TYPE_STRING)
- free(attr->val.string);
+ if (attr->attr->type == ATTR_TYPE_STRING)
+ free((char*)attr->val.string);
list_del(&attr->entry);
free(attr);
}
diff --git a/accel-pptpd/radius/radius.c b/accel-pptpd/radius/radius.c
index 4d020d5b..2e444ded 100644
--- a/accel-pptpd/radius/radius.c
+++ b/accel-pptpd/radius/radius.c
@@ -1,4 +1,5 @@
#include <stdlib.h>
+#include <stdarg.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
@@ -7,30 +8,35 @@
#include "pwdb.h"
#include "radius.h"
+int conf_max_try = 3;
+int conf_timeout = 3;
+char *conf_nas_identifier = "accel-pptpd";
+char *conf_nas_ip_address;
+
static struct ppp_notified_t notified;
static int check_pap(struct radius_pd_t *rpd, const char *username, va_list args)
{
struct rad_req_t *req;
int i, r = PWDB_DENIED;
- int id = va_arg(args, int);
+ //int id = va_arg(args, int);
const char *passwd = va_arg(args, const char *);
- req = rad_req_alloc(rpd, CODE_ACCESS_REQUEST);
+ req = rad_req_alloc(rpd, CODE_ACCESS_REQUEST, username);
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++) {
+ for(i = 0; i < conf_max_try; i++) {
if (rad_req_send(req))
goto out;
- if (rad_req_wait(req, timeout))
+ if (rad_req_wait(req, conf_timeout))
goto out;
- if (req->answer)
+ if (req->reply)
break;
}
@@ -42,27 +48,30 @@ out:
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 id = va_arg(args, int);
+ const uint8_t *challenge = va_arg(args, const uint8_t *);*/
+ return PWDB_DENIED;
}
static int check_mschap_v1(struct radius_pd_t *rpd, const char *username, va_list args)
{
- int id = va_arg(args, int);
+ /*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 flags = va_arg(args, int);*/
+ return PWDB_DENIED;
}
static int check_mschap_v2(struct radius_pd_t *rpd, const char *username, va_list args)
{
- int id = va_arg(args, int);
+ /*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 *);
+ uint8_t *authenticator = va_arg(args, uint8_t *);*/
+ return PWDB_DENIED;
}
static int check(struct pwdb_t *pwdb, struct ppp_t *ppp, const char *username, int type, va_list _args)
@@ -148,8 +157,10 @@ static void __init radius_init(void)
fprintf(stderr, "radius: dictionary not specified\n");
_exit(EXIT_FAILURE);
}
- if (!rad_load_dict(dict))
+ if (!rad_dict_load(dict))
_exit(EXIT_FAILURE);
+
+ pwdb_register(&pwdb);
ppp_register_notified(&notified);
}
diff --git a/accel-pptpd/radius/radius.h b/accel-pptpd/radius/radius.h
index 3fe78621..109981a6 100644
--- a/accel-pptpd/radius/radius.h
+++ b/accel-pptpd/radius/radius.h
@@ -3,6 +3,7 @@
#include <netinet/in.h>
#include "triton.h"
+#include "ppp.h"
#define REQ_LENGTH_MAX 4096
@@ -54,12 +55,14 @@ struct rad_req_attr_t
struct rad_dict_attr_t *attr;
//struct rad_dict_value_t *val;
rad_value_t val;
+ int len;
};
struct rad_packet_t
{
int code;
int id;
+ int len;
struct list_head attrs;
void *buf;
};
@@ -68,23 +71,29 @@ struct rad_req_t
struct triton_md_handler_t hnd;
struct triton_timer_t timeout;
struct rad_packet_t pack;
- struct rad_packet_t *answer;
- const char *server_host;
+ struct rad_packet_t *reply;
+ const char *server_name;
int server_port;
struct radius_pd_t *rpd;
};
+extern int conf_max_try;
+extern int conf_timeout;
+extern char *conf_nas_identifier;
+extern char *conf_nas_ip_address;
+
int rad_dict_load(const char *fname);
void rad_dict_free(struct rad_dict_t *dict);
struct rad_dict_attr_t *rad_dict_find_attr(const char *name);
struct rad_dict_attr_t *rad_dict_find_attr_type(int type);
struct rad_dict_value_t *rad_dict_find_val(struct rad_dict_attr_t *, const char *name);
-struct rad_req_t *rad_rec_alloc(struct radius_pd_t *rpd, int code);
-void rad_rec_free(struct rad_req_t *);
+struct rad_req_t *rad_req_alloc(struct radius_pd_t *rpd, int code, const char *username);
+void rad_req_free(struct rad_req_t *);
int rad_req_send(struct rad_req_t *);
+int rad_req_wait(struct rad_req_t *, int);
int rad_req_add_int(struct rad_req_t *req, const char *name, int val);
int rad_req_add_val(struct rad_req_t *req, const char *name, const char *val, int len);
int rad_req_add_str(struct rad_req_t *req, const char *name, const char *val, int len);
diff --git a/accel-pptpd/radius/req.c b/accel-pptpd/radius/req.c
index d03ea9ae..ae761547 100644
--- a/accel-pptpd/radius/req.c
+++ b/accel-pptpd/radius/req.c
@@ -1,14 +1,21 @@
#include <stdlib.h>
-#include <sys/scket.h>
+#include <string.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
#include "triton.h"
+#include "log.h"
#include "radius.h"
static int rad_req_read(struct triton_md_handler_t *h);
-static void rd_req_timeout(struct triton_timer_t *t);
+static void rad_req_timeout(struct triton_timer_t *t);
-struct rad_req_t *rad_rec_alloc(struct radius_pd_t *rpd, int code, const char *username);
+struct rad_req_t *rad_rec_alloc(struct radius_pd_t *rpd, int code, const char *username)
{
struct rad_req_t *req = malloc(sizeof(*req));
@@ -22,14 +29,14 @@ struct rad_req_t *rad_rec_alloc(struct radius_pd_t *rpd, int code, const char *u
req->pack.len = 20;
req->hnd.fd = -1;
req->hnd.read = rad_req_read;
- req->hnd.timeout.exoire = rad_req_timeout;
+ req->timeout.expire = rad_req_timeout;
if (rad_req_add_str(req, "User-Name", username, strlen(username)))
goto out_err;
if (conf_nas_identifier)
if (rad_req_add_str(req, "NAS-Identifier", conf_nas_identifier, strlen(conf_nas_identifier)))
goto out_err;
- if (rad_req_add_int(req, "NAS-Port-Id", rpd->ppp->unit_idx, 4))
+ if (rad_req_add_int(req, "NAS-Port-Id", rpd->ppp->unit_idx))
goto out_err;
if (rad_req_add_str(req, "NAS-Port-Type", "Sync", 4))
goto out_err;
@@ -39,9 +46,13 @@ struct rad_req_t *rad_rec_alloc(struct radius_pd_t *rpd, int code, const char *u
goto out_err;
return req;
+
+out_err:
+ rad_req_free(req);
+ return NULL;
}
-void rad_rec_free(struct rad_req_t *)
+void rad_rec_free(struct rad_req_t *req)
{
}
@@ -60,17 +71,17 @@ int rad_req_send(struct rad_req_t *req)
if (conf_nas_ip_address) {
addr.sin_family = AF_INET;
- addr.sin_addr.s_addr = htonl(conf_nas_ip_address);
+ addr.sin_addr.s_addr = htonl(inet_addr(conf_nas_ip_address));
if (bind(req->hnd.fd, (struct sockaddr *) &addr, sizeof(addr))) {
log_error("radius:bind: %s\n", strerror(errno));
goto out_err;
}
}
- addr.sin_addr.s_addr = htonl(req->server_name);
+ addr.sin_addr.s_addr = htonl(inet_addr(req->server_name));
addr.sin_port = htons(req->server_port);
- if (connect(req->hnd.fd (struct sockaddr *) &addr, sizeof(addr))) {
+ if (connect(req->hnd.fd, (struct sockaddr *) &addr, sizeof(addr))) {
log_error("radius:connect: %s\n", strerror(errno));
goto out_err;
}
@@ -113,7 +124,7 @@ int rad_req_add_int(struct rad_req_t *req, const char *name, int val)
struct rad_req_attr_t *ra;
struct rad_dict_attr_t *attr;
- if (req->len + 2 + 4 >= REQ_LENGTH_MAX)
+ if (req->pack.len + 2 + 4 >= REQ_LENGTH_MAX)
return -1;
attr = rad_dict_find_attr(name);
@@ -125,9 +136,10 @@ int rad_req_add_int(struct rad_req_t *req, const char *name, int val)
return -1;
ra->attr = attr;
+ ra->len = 4;
ra->val.integer = val;
list_add_tail(&ra->entry, &req->pack.attrs);
- req->len += 2 + 4;
+ req->pack.len += 2 + 4;
return 0;
}
@@ -137,7 +149,7 @@ int rad_req_add_str(struct rad_req_t *req, const char *name, const char *val, in
struct rad_req_attr_t *ra;
struct rad_dict_attr_t *attr;
- if (req->len + 2 + len >= REQ_LENGTH_MAX)
+ if (req->pack.len + 2 + len >= REQ_LENGTH_MAX)
return -1;
attr = rad_dict_find_attr(name);
@@ -149,9 +161,10 @@ int rad_req_add_str(struct rad_req_t *req, const char *name, const char *val, in
return -1;
ra->attr = attr;
- ra->val.string = stdrdup(val);
+ ra->len = len;
+ ra->val.string = strdup(val);
list_add_tail(&ra->entry, &req->pack.attrs);
- req->len += 2 + len;
+ req->pack.len += 2 + len;
return 0;
}
@@ -162,7 +175,7 @@ int rad_req_add_val(struct rad_req_t *req, const char *name, const char *val, in
struct rad_dict_attr_t *attr;
struct rad_dict_value_t *v;
- if (req->len + 2 + len >= REQ_LENGTH_MAX)
+ if (req->pack.len + 2 + len >= REQ_LENGTH_MAX)
return -1;
attr = rad_dict_find_attr(name);
@@ -178,9 +191,10 @@ int rad_req_add_val(struct rad_req_t *req, const char *name, const char *val, in
return -1;
ra->attr = attr;
+ ra->len = len;
ra->val = v->val;
- list_add_tail(&ra->entry, &req->attrs.pack);
- req->len += 2 + len;
+ list_add_tail(&ra->entry, &req->pack.attrs);
+ req->pack.len += 2 + len;
return 0;
}
@@ -189,21 +203,22 @@ static int rad_req_read(struct triton_md_handler_t *h)
{
struct rad_req_t *req = container_of(h, typeof(*req), hnd);
- req->answer = rad_packet_recv(h->hnd.fd);
+ req->reply = rad_packet_recv(h->fd);
+
+ return 0;
}
-static void rd_req_timeout(struct triton_timer_t *t)
+static void rad_req_timeout(struct triton_timer_t *t)
{
}
-int rad_req_wait(struct rad_req_t *req)
+int rad_req_wait(struct rad_req_t *req, int timeout)
{
- if (triton_md_register_handler(req->rpd->ppp->ctrl->ctx, &req->hnd))
- return -1;
+ triton_md_register_handler(req->rpd->ppp->ctrl->ctx, &req->hnd);
if (triton_md_enable_handler(&req->hnd, MD_MODE_READ))
return -1;
- req->timeout.period = conf_timeout * 1000;
- if (triton_timer_add(&req->timeout))
+ req->timeout.period = timeout * 1000;
+ if (triton_timer_add(req->rpd->ppp->ctrl->ctx, &req->timeout, 0))
return -1;
triton_ctx_schedule(&req->hnd, &req->timeout);
diff --git a/accel-pptpd/triton/triton.h b/accel-pptpd/triton/triton.h
index d130d86e..2cc5ccf6 100644
--- a/accel-pptpd/triton/triton.h
+++ b/accel-pptpd/triton/triton.h
@@ -43,6 +43,7 @@ struct conf_sect_t
void triton_register_ctx(struct triton_ctx_t *);
void triton_unregister_ctx(struct triton_ctx_t *);
+void triton_ctx_schedule(struct triton_md_handler_t *, struct triton_timer_t *);
#define MD_MODE_READ 1
#define MD_MODE_WRITE 2