/*
- * $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.
*
*/
*
* Returns: pointer to option on success, NULL otherwise
*/
-
+
static OPTION *find_option(char *optname, unsigned int type)
{
int i;
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;
*/
static int set_option_str(char *filename, int line, OPTION *option, char *p)
-{
+{
if (p)
option->val = (void *) strdup(p);
else
rc_log(LOG_CRIT, "read_config: out of memory");
return (-1);
}
-
- *iptr = atoi(p);
+
+ *iptr = atoi(p);
option->val = (void *) iptr;
return 0;
rc_log(LOG_CRIT, "read_config: out of memory");
return (-1);
}
-
+
*iptr = 0;
p = strtok(p, ", \t");
*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);
}
}
* Function: rc_read_config
*
* Purpose: read the global config file
- *
+ *
* Returns: 0 on success, -1 when failure
*/
{
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);
}
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!");
* Function: rc_conf_str, rc_conf_int, rc_conf_src
*
* Purpose: get the value of a config option
- *
+ *
* Returns: config option value
*/
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();
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();
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();
{
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);
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");
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;
}
}
}
return (-1);
-}
+}
/*
* Function: rc_find_server
* 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;
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);