]> git.ozlabs.org Git - ppp.git/blobdiff - pppd/plugins/radius/radiusclient/lib/buildreq.c
Add these files, used with TDB.
[ppp.git] / pppd / plugins / radius / radiusclient / lib / buildreq.c
index d8a52c9535c3c82144c8196846b3e4e10e2c5370..a24a20ba66c5b1c4ead9e5ed1249c56a0d78c481 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: buildreq.c,v 1.3 2002/04/02 14:09:35 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
  *
@@ -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();
        }
 
@@ -150,7 +192,6 @@ int rc_auth_using_server(SERVER *authserver,
                         char *msg, REQUEST_INFO *info)
 {
        SEND_DATA       data;
-       UINT4           client_id;
        int             result;
        int             i;
        int             timeout = rc_conf_int("radius_timeout");
@@ -160,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
@@ -246,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,
@@ -256,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];
@@ -268,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
@@ -321,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)
@@ -384,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