X-Git-Url: https://git.ozlabs.org/?a=blobdiff_plain;f=pppd%2Fplugins%2Fradius%2Fradiusclient%2Flib%2Fbuildreq.c;h=a24a20ba66c5b1c4ead9e5ed1249c56a0d78c481;hb=4b9bf9ae2701487191810e564aaa4672eb95130e;hp=b7ca07ecd2946a59e29ee2b04dc69a034648c405;hpb=c062322f9e8757b85a3c2281a3190d8af14bcd9b;p=ppp.git diff --git a/pppd/plugins/radius/radiusclient/lib/buildreq.c b/pppd/plugins/radius/radiusclient/lib/buildreq.c index b7ca07e..a24a20b 100644 --- a/pppd/plugins/radius/radiusclient/lib/buildreq.c +++ b/pppd/plugins/radius/radiusclient/lib/buildreq.c @@ -1,5 +1,5 @@ /* - * $Id: buildreq.c,v 1.2 2002/03/01 14:39:19 dfs Exp $ + * $Id: buildreq.c,v 1.5 2003/04/25 08:10:46 fcusack Exp $ * * Copyright (C) 1995,1997 Lars Fenneberg * @@ -15,6 +15,44 @@ unsigned char rc_get_seqnbr(void); +/* + * Function: rc_get_nas_id + * + * Purpose: fills in NAS-Identifier or NAS-IP-Address in request + * + */ + +int rc_get_nas_id(VALUE_PAIR **sendpairs) +{ + UINT4 client_id; + char *nasid; + + nasid = rc_conf_str("nas_identifier"); + if (strlen(nasid)) { + /* + * Fill in NAS-Identifier + */ + if (rc_avpair_add(sendpairs, PW_NAS_IDENTIFIER, nasid, 0, + VENDOR_NONE) == NULL) + return (ERROR_RC); + + return (OK_RC); + + } else { + /* + * Fill in NAS-IP-Address + */ + if ((client_id = rc_own_ipaddress()) == 0) + return (ERROR_RC); + + if (rc_avpair_add(sendpairs, PW_NAS_IP_ADDRESS, &client_id, + 0, VENDOR_NONE) == NULL) + return (ERROR_RC); + } + + return (OK_RC); +} + /* * Function: rc_buildreq * @@ -58,7 +96,7 @@ unsigned char rc_get_seqnbr(void) { FILE *sf; int tries = 1; - int seq_nbr; + int seq_nbr, pos; char *seqfile = rc_conf_str("seqfile"); if ((sf = fopen(seqfile, "a+")) == NULL) @@ -88,9 +126,13 @@ unsigned char rc_get_seqnbr(void) return rc_guess_seqnbr(); } + pos = ftell(sf); rewind(sf); if (fscanf(sf, "%d", &seq_nbr) != 1) { - rc_log(LOG_ERR,"rc_get_seqnbr: fscanf failure: %s", seqfile); + if (pos != ftell(sf)) { + /* file was not empty */ + rc_log(LOG_ERR,"rc_get_seqnbr: fscanf failure: %s", seqfile); + } seq_nbr = rc_guess_seqnbr(); } @@ -120,14 +162,15 @@ unsigned char rc_get_seqnbr(void) */ int rc_auth(UINT4 client_port, VALUE_PAIR *send, VALUE_PAIR **received, - char *msg) + char *msg, REQUEST_INFO *info) { SERVER *authserver = rc_conf_srv("authserver"); if (!authserver) { return (ERROR_RC); } - return rc_auth_using_server(authserver, client_port, send, received, msg); + return rc_auth_using_server(authserver, client_port, send, received, + msg, info); } /* @@ -146,10 +189,9 @@ int rc_auth_using_server(SERVER *authserver, UINT4 client_port, VALUE_PAIR *send, VALUE_PAIR **received, - char *msg) + char *msg, REQUEST_INFO *info) { SEND_DATA data; - UINT4 client_id; int result; int i; int timeout = rc_conf_int("radius_timeout"); @@ -159,14 +201,11 @@ int rc_auth_using_server(SERVER *authserver, data.receive_pairs = NULL; /* - * Fill in NAS-IP-Address + * Fill in NAS-IP-Address or NAS-Identifier */ - if ((client_id = rc_own_ipaddress()) == 0) - return (ERROR_RC); - - if (rc_avpair_add(&(data.send_pairs), PW_NAS_IP_ADDRESS, &client_id, 0, VENDOR_NONE) == NULL) - return (ERROR_RC); + if (rc_get_nas_id(&(data.send_pairs)) == ERROR_RC) + return (ERROR_RC); /* * Fill in NAS-Port @@ -186,7 +225,7 @@ int rc_auth_using_server(SERVER *authserver, rc_buildreq(&data, PW_ACCESS_REQUEST, authserver->name[i], authserver->port[i], timeout, retries); - result = rc_send_server (&data, msg); + result = rc_send_server (&data, msg, info); } *received = data.receive_pairs; @@ -230,7 +269,7 @@ int rc_auth_proxy(VALUE_PAIR *send, VALUE_PAIR **received, char *msg) rc_buildreq(&data, PW_ACCESS_REQUEST, authserver->name[i], authserver->port[i], timeout, retries); - result = rc_send_server (&data, msg); + result = rc_send_server (&data, msg, NULL); } *received = data.receive_pairs; @@ -245,8 +284,8 @@ int rc_auth_proxy(VALUE_PAIR *send, VALUE_PAIR **received, char *msg) * Purpose: Builds an accounting request for port id client_port * with the value_pairs send. You explicitly supply server list. * - * Remarks: NAS-IP-Address, NAS-Port and Acct-Delay-Time get filled - * in by this function, the rest has to be supplied. + * Remarks: NAS-Identifier/NAS-IP-Address, NAS-Port and Acct-Delay-Time get + * filled in by this function, the rest has to be supplied. */ int rc_acct_using_server(SERVER *acctserver, @@ -255,7 +294,6 @@ int rc_acct_using_server(SERVER *acctserver, { SEND_DATA data; VALUE_PAIR *adt_vp; - UINT4 client_id; int result; time_t start_time, dtime; char msg[4096]; @@ -267,14 +305,11 @@ int rc_acct_using_server(SERVER *acctserver, data.receive_pairs = NULL; /* - * Fill in NAS-IP-Address + * Fill in NAS-IP-Address or NAS-Identifier */ - if ((client_id = rc_own_ipaddress()) == 0) - return (ERROR_RC); - - if (rc_avpair_add(&(data.send_pairs), PW_NAS_IP_ADDRESS, &client_id, 0, VENDOR_NONE) == NULL) - return (ERROR_RC); + if (rc_get_nas_id(&(data.send_pairs)) == ERROR_RC) + return (ERROR_RC); /* * Fill in NAS-Port @@ -306,7 +341,7 @@ int rc_acct_using_server(SERVER *acctserver, dtime = time(NULL) - start_time; rc_avpair_assign(adt_vp, &dtime, 0); - result = rc_send_server (&data, msg); + result = rc_send_server (&data, msg, NULL); } rc_avpair_free(data.receive_pairs); @@ -320,8 +355,8 @@ int rc_acct_using_server(SERVER *acctserver, * Purpose: Builds an accounting request for port id client_port * with the value_pairs send * - * Remarks: NAS-IP-Address, NAS-Port and Acct-Delay-Time get filled - * in by this function, the rest has to be supplied. + * Remarks: NAS-Identifier/NAS-IP-Address, NAS-Port and Acct-Delay-Time get + * filled in by this function, the rest has to be supplied. */ int rc_acct(UINT4 client_port, VALUE_PAIR *send) @@ -363,7 +398,7 @@ int rc_acct_proxy(VALUE_PAIR *send) rc_buildreq(&data, PW_ACCOUNTING_REQUEST, acctserver->name[i], acctserver->port[i], timeout, retries); - result = rc_send_server (&data, msg); + result = rc_send_server (&data, msg, NULL); } rc_avpair_free(data.receive_pairs); @@ -383,20 +418,19 @@ int rc_check(char *host, unsigned short port, char *msg) { SEND_DATA data; int result; - UINT4 client_id, service_type; + UINT4 service_type; int timeout = rc_conf_int("radius_timeout"); int retries = rc_conf_int("radius_retries"); data.send_pairs = data.receive_pairs = NULL; /* - * Fill in NAS-IP-Address, although it isn't neccessary + * Fill in NAS-IP-Address or NAS-Identifier, + * although it isn't neccessary */ - if ((client_id = rc_own_ipaddress()) == 0) - return (ERROR_RC); - - rc_avpair_add(&(data.send_pairs), PW_NAS_IP_ADDRESS, &client_id, 0, VENDOR_NONE); + if (rc_get_nas_id(&(data.send_pairs)) == ERROR_RC) + return (ERROR_RC); /* * Fill in Service-Type @@ -406,7 +440,7 @@ int rc_check(char *host, unsigned short port, char *msg) rc_avpair_add(&(data.send_pairs), PW_SERVICE_TYPE, &service_type, 0, VENDOR_NONE); rc_buildreq(&data, PW_STATUS_SERVER, host, port, timeout, retries); - result = rc_send_server (&data, msg); + result = rc_send_server (&data, msg, NULL); rc_avpair_free(data.receive_pairs);