/*
- * $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
*
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
*
{
FILE *sf;
int tries = 1;
- int seq_nbr;
+ int seq_nbr, pos;
char *seqfile = rc_conf_str("seqfile");
if ((sf = fopen(seqfile, "a+")) == NULL)
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();
}
*/
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);
}
/*
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");
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
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;
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;
* 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,
{
SEND_DATA data;
VALUE_PAIR *adt_vp;
- UINT4 client_id;
int result;
time_t start_time, dtime;
char msg[4096];
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
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);
* 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)
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);
{
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
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);