#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
#include <string.h>
#include <syslog.h>
#include <unistd.h>
#include "auth.h"
#include "ha_config.h"
#include "ha.h"
#include "fileio.h"
#include "util.h"
Include dependency graph for ha_config.c:
Go to the source code of this file.
Data Structures | |
struct | load_ha_data |
Defines | |
#define | ASSERT assert |
Functions | |
void | cleanup_config (struct ha_config *cfg) |
int | load_config (struct ha_config *cfg, char *program_name, char *config_file) |
#define ASSERT assert |
Definition at line 26 of file ha_config.c.
void cleanup_config | ( | struct ha_config * | cfg | ) |
Definition at line 47 of file ha_config.c.
References ha_config::authorized_list, ha_config::fa_spi_list, interface_entry::icmp_sock, ha_config::interfaces, spi_entry::spi, ha_config::spi_list, interface_entry::udp_bc_sock, interface_entry::udp_bc_sock2, and interface_entry::udp_sock.
Referenced by load_config().
00048 { 00049 struct spi_entry *spi; 00050 struct fa_spi_entry *fa_spi; 00051 struct authorized_entry *auth; 00052 struct interface_entry *iface; 00053 00054 if (cfg == NULL) return; 00055 00056 spi = (struct spi_entry *) list_remove_first(&cfg->spi_list); 00057 while (spi != NULL) { 00058 free(spi); 00059 spi = (struct spi_entry *) list_remove_first(&cfg->spi_list); 00060 } 00061 00062 /* remove all from authorized list */ 00063 auth = (struct authorized_entry *) 00064 list_remove_first(&cfg->authorized_list); 00065 while (auth != NULL) { 00066 free(auth); 00067 auth = (struct authorized_entry *) 00068 list_remove_first(&cfg->authorized_list); 00069 } 00070 00071 fa_spi = (struct fa_spi_entry *) list_remove_first(&cfg->fa_spi_list); 00072 while (fa_spi != NULL) { 00073 free(fa_spi); 00074 fa_spi = (struct fa_spi_entry *) 00075 list_remove_first(&cfg->fa_spi_list); 00076 } 00077 00078 iface = (struct interface_entry *) 00079 list_remove_first(&cfg->interfaces); 00080 while (iface != NULL) { 00081 if (iface->icmp_sock >= 0) 00082 close(iface->icmp_sock); 00083 if (iface->udp_sock >= 0) 00084 close(iface->udp_sock); 00085 if (iface->udp_bc_sock >= 0) 00086 close(iface->udp_bc_sock); 00087 if (iface->udp_bc_sock2 >= 0) 00088 close(iface->udp_bc_sock2); 00089 free(iface); 00090 iface = (struct interface_entry *) 00091 list_remove_first(&cfg->interfaces); 00092 } 00093 }
int load_config | ( | struct ha_config * | cfg, | |
char * | program_name, | |||
char * | config_file | |||
) |
Definition at line 97 of file ha_config.c.
References ASSERT, ha_config::authorized_list, load_ha_data::cfg, cleanup_config(), ha_config::enable_reverse_tunneling, ha_config::enable_triangle_tunneling, ha_config::fa_spi_list, FALSE, HA_DEFAULT_MAX_BINDINGS, HA_DEFAULT_REG_ERROR_REPLY_INTERVAL, HA_DEFAULT_REG_PORT, HA_DEFAULT_SYSLOG_FACILITY, ha_config::ha_default_tunnel_lifetime, HA_DEFAULT_TUNNEL_LIFETIME, HASH_METHOD_CHECK, ha_config::interfaces, ha_config::max_bindings, load_ha_data::process_authorized_list, load_ha_data::process_fa_spi_list, load_ha_data::process_interfaces, load_ha_data::process_spi_list, ha_config::pubkey_hash_method, ha_config::reg_error_reply_interval, ha_config::socket_priority, ha_config::spi_list, ha_config::syslog_facility, TRUE, and ha_config::udpport.
00098 { 00099 FILE *file; 00100 struct load_ha_data ha; 00101 00102 ASSERT(cfg); 00103 ha.cfg = cfg; 00104 memset(cfg, 0, sizeof(struct ha_config)); 00105 ha.process_spi_list = FALSE; 00106 list_init(&cfg->spi_list); 00107 ha.process_authorized_list = FALSE; 00108 list_init(&cfg->authorized_list); 00109 ha.process_fa_spi_list = FALSE; 00110 list_init(&cfg->fa_spi_list); 00111 ha.process_interfaces = FALSE; 00112 list_init(&cfg->interfaces); 00113 00114 /* set default values */ 00115 cfg->max_bindings = HA_DEFAULT_MAX_BINDINGS; 00116 cfg->ha_default_tunnel_lifetime = HA_DEFAULT_TUNNEL_LIFETIME; 00117 cfg->reg_error_reply_interval = HA_DEFAULT_REG_ERROR_REPLY_INTERVAL; 00118 cfg->syslog_facility = HA_DEFAULT_SYSLOG_FACILITY; 00119 cfg->udpport = HA_DEFAULT_REG_PORT; 00120 cfg->socket_priority = -1; 00121 cfg->enable_triangle_tunneling = TRUE; 00122 cfg->enable_reverse_tunneling = TRUE; 00123 cfg->pubkey_hash_method = HASH_METHOD_CHECK; 00124 00125 file = fopen(config_file, "r"); 00126 if (file == NULL) { 00127 fprintf(stderr, 00128 "%s: Could not open configuration file '%s'.\n", 00129 program_name, config_file); 00130 return FALSE; 00131 } 00132 if (load_data(&ha, file, process_load_ha) == FALSE) { 00133 fprintf(stderr, 00134 "%s: Error while interpreting file '%s'!\n", 00135 program_name, config_file); 00136 fclose(file); 00137 cleanup_config(cfg); 00138 return FALSE; 00139 } 00140 fclose(file); 00141 00142 openlog("home agent", LOG_PID | LOG_CONS, cfg->syslog_facility); 00143 00144 return TRUE; 00145 }
Here is the call graph for this function: