]> git.ozlabs.org Git - ppp.git/blobdiff - pppd/plugins/radius/radiusclient/lib/config.c
Large patch from Frank Cusack <fcusack@fcusack.com> to add proper
[ppp.git] / pppd / plugins / radius / radiusclient / lib / config.c
index 0b78c862074f49862eb126bd64639857886ffec3..724edbec463efd62140b2e476cf417818fa282b5 100644 (file)
@@ -1,15 +1,15 @@
 /*
- * $Id: config.c,v 1.1 2002/01/22 16:03:02 dfs Exp $
+ * $Id: config.c,v 1.2 2002/02/27 15:51:20 dfs Exp $
  *
  * Copyright (C) 1995,1996,1997 Lars Fenneberg
  *
  * Copyright 1992 Livingston Enterprises, Inc.
  *
- * Copyright 1992,1993, 1994,1995 The Regents of the University of Michigan 
+ * Copyright 1992,1993, 1994,1995 The Regents of the University of Michigan
  * and Merit Network, Inc. All Rights Reserved
  *
- * See the file COPYRIGHT for the respective terms and conditions. 
- * If the file is missing contact me at lf@elemental.net 
+ * See the file COPYRIGHT for the respective terms and conditions.
+ * If the file is missing contact me at lf@elemental.net
  * and I'll send you a copy.
  *
  */
@@ -28,7 +28,7 @@ static int test_config(char *);
  *
  * Returns: pointer to option on success, NULL otherwise
  */
+
 static OPTION *find_option(char *optname, unsigned int type)
 {
        int i;
@@ -37,7 +37,7 @@ static OPTION *find_option(char *optname, unsigned int type)
        for (i = 0; i < num_options; i++) {
                if (!strcmp(config_options[i].name, optname) &&
                    (config_options[i].type & type))
-                       return &config_options[i];
+                       return &config_options[i];
        }
 
        return NULL;
@@ -52,7 +52,7 @@ static OPTION *find_option(char *optname, unsigned int type)
  */
 
 static int set_option_str(char *filename, int line, OPTION *option, char *p)
-{ 
+{
        if (p)
                option->val = (void *) strdup(p);
        else
@@ -74,8 +74,8 @@ static int set_option_int(char *filename, int line, OPTION *option, char *p)
                rc_log(LOG_CRIT, "read_config: out of memory");
                return (-1);
        }
-       
-       *iptr = atoi(p);                                
+
+       *iptr = atoi(p);
        option->val = (void *) iptr;
 
        return 0;
@@ -144,7 +144,7 @@ static int set_option_auo(char *filename, int line, OPTION *option, char *p)
                        rc_log(LOG_CRIT, "read_config: out of memory");
                        return (-1);
        }
-                       
+
        *iptr = 0;
        p = strtok(p, ", \t");
 
@@ -154,19 +154,19 @@ static int set_option_auo(char *filename, int line, OPTION *option, char *p)
                        *iptr = AUTH_RADIUS_FST;
        else {
                rc_log(LOG_ERR,"%s: auth_order: unknown keyword: %s", filename, p);
-               return (-1); 
+               return (-1);
        }
-                       
+
        p = strtok(NULL, ", \t");
-                       
+
        if (p && (*p != '\0')) {
                if ((*iptr & AUTH_RADIUS_FST) && !strcmp(p, "local"))
                        *iptr = (*iptr) | AUTH_LOCAL_SND;
                else if ((*iptr & AUTH_LOCAL_FST) && !strcmp(p, "radius"))
-                       *iptr = (*iptr) | AUTH_RADIUS_SND;   
+                       *iptr = (*iptr) | AUTH_RADIUS_SND;
                else {
                        rc_log(LOG_ERR,"%s: auth_order: unknown or unexpected keyword: %s", filename, p);
-                       return (-1); 
+                       return (-1);
                }
        }
 
@@ -180,7 +180,7 @@ static int set_option_auo(char *filename, int line, OPTION *option, char *p)
  * Function: rc_read_config
  *
  * Purpose: read the global config file
- * 
+ *
  * Returns: 0 on success, -1 when failure
  */
 
@@ -202,20 +202,20 @@ int rc_read_config(char *filename)
        {
                line++;
                p = buffer;
-               
+
                if ((*p == '\n') || (*p == '#') || (*p == '\0'))
                        continue;
 
                p[strlen(p)-1] = '\0';
-               
-               
+
+
                if ((pos = strcspn(p, "\t ")) == 0) {
                        rc_log(LOG_ERR, "%s: line %d: bogus format: %s", filename, line, p);
                        return (-1);
-               } 
-               
+               }
+
                p[pos] = '\0';
-               
+
                if ((option = find_option(p, OT_ANY)) == NULL) {
                        rc_log(LOG_ERR, "%s: line %d: unrecognized keyword: %s", filename, line, p);
                        return (-1);
@@ -227,25 +227,25 @@ int rc_read_config(char *filename)
                }
 
                p += pos+1;
-               while (isspace(*p)) 
+               while (isspace(*p))
                        p++;
 
                switch (option->type) {
                        case OT_STR:
                                 if (set_option_str(filename, line, option, p) < 0)
-                                       return (-1);
-                               break;                                  
+                                       return (-1);
+                               break;
                        case OT_INT:
                                 if (set_option_int(filename, line, option, p) < 0)
-                                       return (-1);
+                                       return (-1);
                                break;
                        case OT_SRV:
                                 if (set_option_srv(filename, line, option, p) < 0)
-                                       return (-1);
+                                       return (-1);
                                break;
                        case OT_AUO:
                                 if (set_option_auo(filename, line, option, p) < 0)
-                                       return (-1);
+                                       return (-1);
                                break;
                        default:
                                rc_log(LOG_CRIT, "rc_read_config: impossible case branch!");
@@ -261,7 +261,7 @@ int rc_read_config(char *filename)
  * Function: rc_conf_str, rc_conf_int, rc_conf_src
  *
  * Purpose: get the value of a config option
- * 
+ *
  * Returns: config option value
  */
 
@@ -270,9 +270,9 @@ char *rc_conf_str(char *optname)
        OPTION *option;
 
        option = find_option(optname, OT_STR);
-       
+
        if (option != NULL) {
-               return (char *)option->val;     
+               return (char *)option->val;
        } else {
                rc_log(LOG_CRIT, "rc_conf_str: unkown config option requested: %s", optname);
                abort();
@@ -284,9 +284,9 @@ int rc_conf_int(char *optname)
        OPTION *option;
 
        option = find_option(optname, OT_INT|OT_AUO);
-       
+
        if (option != NULL) {
-               return *((int *)option->val);   
+               return *((int *)option->val);
        } else {
                rc_log(LOG_CRIT, "rc_conf_int: unkown config option requested: %s", optname);
                abort();
@@ -298,9 +298,9 @@ SERVER *rc_conf_srv(char *optname)
        OPTION *option;
 
        option = find_option(optname, OT_SRV);
-       
+
        if (option != NULL) {
-               return (SERVER *)option->val;   
+               return (SERVER *)option->val;
        } else {
                rc_log(LOG_CRIT, "rc_conf_srv: unkown config option requested: %s", optname);
                abort();
@@ -336,7 +336,7 @@ static int test_config(char *filename)
        {
                rc_log(LOG_ERR,"%s: no servers file specified", filename);
                return (-1);
-       }                                                                         
+       }
        if (!rc_conf_str("dictionary"))
        {
                rc_log(LOG_ERR,"%s: no dictionary specified", filename);
@@ -348,11 +348,11 @@ static int test_config(char *filename)
                rc_log(LOG_ERR,"%s: radius_timeout <= 0 is illegal", filename);
                return (-1);
        }
-       if (rc_conf_int("radius_retries") <= 0) 
+       if (rc_conf_int("radius_retries") <= 0)
        {
                rc_log(LOG_ERR,"%s: radius_retries <= 0 is illegal", filename);
                return (-1);
-       }       
+       }
 
 #if 0
        file = rc_conf_str("login_local");
@@ -378,32 +378,32 @@ static int test_config(char *filename)
                return (-1);
        }
 #endif
-       
+
        if (rc_conf_int("login_tries") <= 0)
        {
                rc_log(LOG_ERR,"%s: login_tries <= 0 is illegal", filename);
                return (-1);
-       }       
+       }
        if (rc_conf_str("seqfile") == NULL)
        {
                rc_log(LOG_ERR,"%s: seqfile not specified", filename);
                return (-1);
-       }       
+       }
        if (rc_conf_int("login_timeout") <= 0)
        {
                rc_log(LOG_ERR,"%s: login_timeout <= 0 is illegal", filename);
                return (-1);
-       }       
+       }
        if (rc_conf_str("mapfile") == NULL)
        {
                rc_log(LOG_ERR,"%s: mapfile not specified", filename);
                return (-1);
-       }       
+       }
        if (rc_conf_str("nologin") == NULL)
        {
                rc_log(LOG_ERR,"%s: nologin not specified", filename);
                return (-1);
-       }       
+       }
 
        return 0;
 }
@@ -446,7 +446,7 @@ static int find_match (UINT4 *ip_addr, char *hostname)
                }
        }
        return (-1);
-} 
+}
 
 /*
  * Function: rc_find_server
@@ -456,10 +456,10 @@ static int find_match (UINT4 *ip_addr, char *hostname)
  * Returns: 0 on success, -1 on failure
  *
  */
+
 int rc_find_server (char *server_name, UINT4 *ip_addr, char *secret)
 {
-       UINT4           myipaddr = 0;
+       UINT4   myipaddr = 0;
        int             len;
        int             result;
        FILE           *clientfd;
@@ -478,7 +478,7 @@ int rc_find_server (char *server_name, UINT4 *ip_addr, char *secret)
                rc_log(LOG_ERR, "rc_find_server: couldn't open file: %s: %s", strerror(errno), rc_conf_str("servers"));
                return (-1);
        }
-       
+
        if ((myipaddr = rc_own_ipaddress()) == 0)
                return (-1);