X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fsrc%2Fauths%2Fcall_radius.c;h=c3637436dc168da653ef39cdfa04035b77b75fe6;hb=14e2dbbf0ec482f9fa5dd5a4fb6f2954a27f21eb;hp=5cfcd4eb601244c58927669a7bd3a9111402e620;hpb=0756eb3cb50d73a77b486e47528f7cb1bffdb299;p=user%2Fhenk%2Fcode%2Fexim.git diff --git a/src/src/auths/call_radius.c b/src/src/auths/call_radius.c index 5cfcd4eb6..c3637436d 100644 --- a/src/src/auths/call_radius.c +++ b/src/src/auths/call_radius.c @@ -1,15 +1,23 @@ -/* $Cambridge: exim/src/src/auths/call_radius.c,v 1.1 2004/10/07 13:10:01 ph10 Exp $ */ - /************************************************* * Exim - an Internet mail transport agent * *************************************************/ -/* Copyright (c) University of Cambridge 1995 - 2004 */ +/* Copyright (c) University of Cambridge 1995 - 2016 */ /* See the file NOTICE for conditions of use and distribution. */ /* This file was originally supplied by Ian Kirk. The libradius support came from Alex Kiernan. */ +/* ugly hack to work around redefinition of ENV by radiusclient.h and + * db.h: define _DB_H_ so the db.h include thinks it's already included, + * we can get away with it like this, since this file doesn't use any db + * functions. */ +#ifndef _DB_H_ +# define _DB_H_ 1 +# define _DB_EXT_PROT_IN_ 1 +# define DB void +#endif + #include "../exim.h" /* This module contains functions that call the Radius authentication @@ -22,22 +30,30 @@ RADIUS_CONFIG_FILE is defined. However, some compilers don't like compiling empty modules, so keep them happy with a dummy when skipping the rest. Make it reference itself to stop picky compilers complaining that it is unused, and put in a dummy argument to stop even pickier compilers complaining about infinite -loops. */ +loops. Then use a mutually-recursive pair as gcc is just getting stupid. */ #ifndef RADIUS_CONFIG_FILE -static void dummy(int x) { dummy(x-1); } +static void dummy(int x); +static void dummy2(int x) { dummy(x-1); } +static void dummy(int x) { dummy2(x-1); } #else /* RADIUS_CONFIG_FILE */ -/* Two different Radius libraries are supported. The default is radiusclient. */ +/* Two different Radius libraries are supported. The default is radiusclient, +using its original API. At release 0.4.0 the API changed. */ #ifdef RADIUS_LIB_RADLIB #include #else - #ifndef RADIUS_LIB_RADIUSCLIENT - #define RADIUS_LIB_RADIUSCLIENT + #if !defined(RADIUS_LIB_RADIUSCLIENT) && !defined(RADIUS_LIB_RADIUSCLIENTNEW) + # define RADIUS_LIB_RADIUSCLIENT + #endif + + #ifdef RADIUS_LIB_RADIUSCLIENTNEW + # include + #else + # include #endif - #include #endif @@ -59,20 +75,23 @@ Returns: OK if authentication succeeded */ int -auth_call_radius(uschar *s, uschar **errptr) +auth_call_radius(const uschar *s, uschar **errptr) { uschar *user; -uschar *radius_args = s; +const uschar *radius_args = s; int result; int sep = 0; #ifdef RADIUS_LIB_RADLIB -struct rad_handle *h; + struct rad_handle *h; #else -VALUE_PAIR *send = NULL; -VALUE_PAIR *received; -unsigned int service = PW_AUTHENTICATE_ONLY; -char msg[4096]; + #ifdef RADIUS_LIB_RADIUSCLIENTNEW + rc_handle *h; + #endif + VALUE_PAIR *send = NULL; + VALUE_PAIR *received; + unsigned int service = PW_AUTHENTICATE_ONLY; + char msg[4096]; #endif @@ -87,10 +106,11 @@ DEBUG(D_auth) debug_printf("Running RADIUS authentication for user \"%s\" " /* Authenticate using the radiusclient library */ -#ifdef RADIUS_LIB_RADIUSCLIENT +#ifndef RADIUS_LIB_RADLIB rc_openlog("exim"); +#ifdef RADIUS_LIB_RADIUSCLIENT if (rc_read_config(RADIUS_CONFIG_FILE) != 0) *errptr = string_sprintf("RADIUS: can't open %s", RADIUS_CONFIG_FILE); @@ -106,13 +126,38 @@ else if (rc_avpair_add(&send, PW_USER_PASSWORD, CS radius_args, 0) == NULL) else if (rc_avpair_add(&send, PW_SERVICE_TYPE, &service, 0) == NULL) *errptr = string_sprintf("RADIUS: add service type failed\n"); +#else /* RADIUS_LIB_RADIUSCLIENT unset => RADIUS_LIB_RADIUSCLIENT2 */ + +if ((h = rc_read_config(RADIUS_CONFIG_FILE)) == NULL) + *errptr = string_sprintf("RADIUS: can't open %s", RADIUS_CONFIG_FILE); + +else if (rc_read_dictionary(h, rc_conf_str(h, "dictionary")) != 0) + *errptr = string_sprintf("RADIUS: can't read dictionary"); + +else if (rc_avpair_add(h, &send, PW_USER_NAME, user, Ustrlen(user), 0) == NULL) + *errptr = string_sprintf("RADIUS: add user name failed\n"); + +else if (rc_avpair_add(h, &send, PW_USER_PASSWORD, CS radius_args, + Ustrlen(radius_args), 0) == NULL) + *errptr = string_sprintf("RADIUS: add password failed\n"); + +else if (rc_avpair_add(h, &send, PW_SERVICE_TYPE, &service, 0, 0) == NULL) + *errptr = string_sprintf("RADIUS: add service type failed\n"); + +#endif /* RADIUS_LIB_RADIUSCLIENT */ + if (*errptr != NULL) { DEBUG(D_auth) debug_printf("%s\n", *errptr); return ERROR; } +#ifdef RADIUS_LIB_RADIUSCLIENT result = rc_auth(0, send, &received, msg); +#else +result = rc_auth(h, 0, send, &received, msg); +#endif + DEBUG(D_auth) debug_printf("RADIUS code returned %d\n", result); switch (result) @@ -120,6 +165,7 @@ switch (result) case OK_RC: return OK; + case REJECT_RC: case ERROR_RC: return FAIL; @@ -133,7 +179,7 @@ switch (result) return ERROR; } -#else /* RADIUS_LIB_RADIUSCLIENT not set => RADIUS_LIB_RADLIB is set */ +#else /* RADIUS_LIB_RADLIB is set */ /* Authenticate using the libradius library */ @@ -147,7 +193,8 @@ if (rad_config(h, RADIUS_CONFIG_FILE) != 0 || rad_create_request(h, RAD_ACCESS_REQUEST) != 0 || rad_put_string(h, RAD_USER_NAME, CS user) != 0 || rad_put_string(h, RAD_USER_PASSWORD, CS radius_args) != 0 || - rad_put_int(h, RAD_SERVICE_TYPE, RAD_AUTHENTICATE_ONLY) != 0) + rad_put_int(h, RAD_SERVICE_TYPE, RAD_AUTHENTICATE_ONLY) != 0 || + rad_put_string(h, RAD_NAS_IDENTIFIER, CS primary_hostname) != 0) { *errptr = string_sprintf("RADIUS: %s", rad_strerror(h)); result = ERROR;