diff options
author | Kozlov Dmitry <xeb@mail.ru> | 2013-04-11 14:05:15 +0400 |
---|---|---|
committer | Kozlov Dmitry <xeb@mail.ru> | 2013-04-11 14:05:15 +0400 |
commit | 4c709610cfb97f196b8b279fe4dedf19ae569b03 (patch) | |
tree | b8fc9e8995d80eb713b0eab13658000f366e4687 | |
parent | ce3bd57194cedb7b9a1f6f35ad1b3586389cc7b9 (diff) | |
download | accel-ppp-4c709610cfb97f196b8b279fe4dedf19ae569b03.tar.gz accel-ppp-4c709610cfb97f196b8b279fe4dedf19ae569b03.zip |
radius: implemented default-realm option
-rw-r--r-- | accel-pppd/accel-ppp.conf.5 | 3 | ||||
-rw-r--r-- | accel-pppd/radius/radius.c | 26 |
2 files changed, 27 insertions, 2 deletions
diff --git a/accel-pppd/accel-ppp.conf.5 b/accel-pppd/accel-ppp.conf.5 index 3b351bbe..eddb543d 100644 --- a/accel-pppd/accel-ppp.conf.5 +++ b/accel-pppd/accel-ppp.conf.5 @@ -392,6 +392,9 @@ Specifies timeout of accounting interim update. .BI "acct-delay-time=" 0|1 Specifies whether radius client should include Acct-Delay-Time attribute to accounting requests (default 0). .TP +.BI "default-realme=" realm +Append specified realm to username. +.TP .SH [log] .br Configuration of log and log_file modules. diff --git a/accel-pppd/radius/radius.c b/accel-pppd/radius/radius.c index d7f30f28..57916f07 100644 --- a/accel-pppd/radius/radius.c +++ b/accel-pppd/radius/radius.c @@ -41,6 +41,9 @@ int conf_accounting; int conf_fail_time; int conf_req_limit; +static const char *conf_default_realm; +static int conf_default_realm_len; + static LIST_HEAD(sessions); static pthread_rwlock_t sessions_lock = PTHREAD_RWLOCK_INITIALIZER; @@ -146,12 +149,27 @@ int rad_proc_attrs(struct rad_req_t *req) return res; } -static int check(struct pwdb_t *pwdb, struct ppp_t *ppp, const char *username, int type, va_list _args) +static int rad_pwdb_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 radius_pd_t *rpd = find_pd(ppp); + char username1[256]; + + if (conf_default_realm && !strchr(username, '@')) { + int len = strlen(username); + if (len + conf_default_realm_len >= 256 - 2) { + log_ppp_error("radius: username is too large to append realm\n"); + return PWDB_DENIED; + } + + memcpy(username1, username, len); + username1[len] = '@'; + memcpy(username1 + len + 1, conf_default_realm, conf_default_realm_len); + username1[len + 1 + conf_default_realm_len] = 0; + username = username1; + } va_copy(args, _args); @@ -447,7 +465,7 @@ static struct ipdb_t ipdb = { }; static struct pwdb_t pwdb = { - .check = check, + .check = rad_pwdb_check, }; static int parse_server(const char *opt, in_addr_t *addr, int *port, char **secret) @@ -559,6 +577,10 @@ static int load_config(void) opt = conf_get_opt("radius", "req-limit"); if (opt) conf_req_limit = atoi(opt); + + conf_default_realm = conf_get_opt("radius", "default-realm"); + if (conf_default_realm) + conf_default_realm_len = strlen(conf_default_realm); return 0; } |