Skip to content

Commit ceae3fd

Browse files
author
sinkcup
committed
resolve #78
1 parent e12c402 commit ceae3fd

File tree

3 files changed

+65
-13
lines changed

3 files changed

+65
-13
lines changed

src/centralserver.c

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -160,15 +160,10 @@ _connect_auth_server(int level)
160160
{
161161
s_config *config = config_get_config();
162162
t_auth_serv *auth_server = NULL;
163+
t_popular_server *popular_server = NULL;
163164
struct in_addr *h_addr;
164165
int num_servers = 0;
165166
char *hostname = NULL;
166-
char *popular_servers[] = {
167-
"www.google.com",
168-
"www.yahoo.com",
169-
NULL
170-
};
171-
char **popularserver;
172167
char *ip;
173168
struct sockaddr_in their_addr;
174169
int sockfd;
@@ -208,20 +203,18 @@ _connect_auth_server(int level)
208203
if (!h_addr) {
209204
/*
210205
* DNS resolving it failed
211-
*
212-
* Can we resolve any of the popular servers ?
213206
*/
214207
debug(LOG_DEBUG, "Level %d: Resolving auth server [%s] failed", level, hostname);
215208

216-
for (popularserver = popular_servers; *popularserver; popularserver++) {
217-
debug(LOG_DEBUG, "Level %d: Resolving popular server [%s]", level, *popularserver);
218-
h_addr = wd_gethostbyname(*popularserver);
209+
for (popular_server = config->popular_servers; popular_server; popular_server = popular_server->next) {
210+
debug(LOG_DEBUG, "Level %d: Resolving popular server [%s]", level, popular_server->hostname);
211+
h_addr = wd_gethostbyname(popular_server->hostname);
219212
if (h_addr) {
220-
debug(LOG_DEBUG, "Level %d: Resolving popular server [%s] succeeded = [%s]", level, *popularserver,
213+
debug(LOG_DEBUG, "Level %d: Resolving popular server [%s] succeeded = [%s]", level, popular_server->hostname,
221214
inet_ntoa(*h_addr));
222215
break;
223216
} else {
224-
debug(LOG_DEBUG, "Level %d: Resolving popular server [%s] failed", level, *popularserver);
217+
debug(LOG_DEBUG, "Level %d: Resolving popular server [%s] failed", level, popular_server->hostname);
225218
}
226219
}
227220

src/conf.c

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ typedef enum {
9797
oFirewallRule,
9898
oFirewallRuleSet,
9999
oTrustedMACList,
100+
oPopularServers,
100101
oHtmlMessageFile,
101102
oProxyPort,
102103
oSSLPeerVerification,
@@ -141,6 +142,7 @@ static const struct {
141142
"firewallruleset", oFirewallRuleSet}, {
142143
"firewallrule", oFirewallRule}, {
143144
"trustedmaclist", oTrustedMACList}, {
145+
"popularservers", oPopularServers}, {
144146
"htmlmessagefile", oHtmlMessageFile}, {
145147
"proxyport", oProxyPort}, {
146148
"sslpeerverification", oSSLPeerVerification}, {
@@ -193,6 +195,7 @@ config_init(void)
193195
config.internal_sock = safe_strdup(DEFAULT_INTERNAL_SOCK);
194196
config.rulesets = NULL;
195197
config.trustedmaclist = NULL;
198+
config.popular_servers = NULL;
196199
config.proxy_port = 0;
197200
config.ssl_certs = safe_strdup(DEFAULT_AUTHSERVSSLCERTPATH);
198201
config.ssl_verify = DEFAULT_AUTHSERVSSLPEERVER;
@@ -707,6 +710,9 @@ config_read(const char *filename)
707710
case oTrustedMACList:
708711
parse_trusted_mac_list(p1);
709712
break;
713+
case oPopularServers:
714+
parse_popular_servers(p1);
715+
break;
710716
case oHTTPDName:
711717
config.httpdname = safe_strdup(p1);
712718
break;
@@ -889,6 +895,48 @@ parse_trusted_mac_list(const char *ptr)
889895

890896
}
891897

898+
void
899+
parse_popular_servers(const char *ptr)
900+
{
901+
char *ptrcopy = NULL;
902+
char *hostname = NULL;
903+
t_popular_server *p = NULL;
904+
905+
debug(LOG_DEBUG, "Parsing string [%s] for popular servers", ptr);
906+
907+
// max length of domain name is 253 characters
908+
hostname = safe_malloc(254);
909+
910+
/* strsep modifies original, so let's make a copy */
911+
ptrcopy = safe_strdup(ptr);
912+
913+
while ((hostname = strsep(&ptrcopy, ", "))) {
914+
if (strcmp(hostname, "") == 0) {
915+
continue;
916+
}
917+
debug(LOG_DEBUG, "Adding Popular Server [%s] to list", hostname);
918+
919+
if (config.popular_servers == NULL) {
920+
config.popular_servers = safe_malloc(sizeof(t_popular_server));
921+
config.popular_servers->hostname = safe_strdup(hostname);
922+
config.popular_servers->next = NULL;
923+
} else {
924+
p = config.popular_servers;
925+
/* Advance to the last entry */
926+
while (p->next != NULL) {
927+
p = p->next;
928+
}
929+
p->next = safe_malloc(sizeof(t_popular_server));
930+
p = p->next;
931+
p->hostname = safe_strdup(hostname);
932+
p->next = NULL;
933+
}
934+
}
935+
936+
free(ptrcopy);
937+
free(hostname);
938+
}
939+
892940
/** Verifies if the configuration is complete and valid. Terminates the program if it isn't */
893941
void
894942
config_validate(void)

src/conf.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,14 @@ typedef struct _trusted_mac_t {
143143
struct _trusted_mac_t *next;
144144
} t_trusted_mac;
145145

146+
/**
147+
* Popular Servers
148+
*/
149+
typedef struct _popular_server_t {
150+
char *hostname;
151+
struct _popular_server_t *next;
152+
} t_popular_server;
153+
146154
/**
147155
* Configuration structure
148156
*/
@@ -185,6 +193,7 @@ typedef struct {
185193
char *ssl_cipher_list; /**< @brief List of SSL ciphers allowed. Optional. */
186194
t_firewall_ruleset *rulesets; /**< @brief firewall rules */
187195
t_trusted_mac *trustedmaclist; /**< @brief list of trusted macs */
196+
t_popular_server *popular_servers; /**< @brief list of popular servers */
188197
} s_config;
189198

190199
/** @brief Get the current gateway configuration */
@@ -213,6 +222,8 @@ t_firewall_rule *get_ruleset(const char *);
213222

214223
void parse_trusted_mac_list(const char *);
215224

225+
void parse_popular_servers(const char *);
226+
216227
#define LOCK_CONFIG() do { \
217228
debug(LOG_DEBUG, "Locking config"); \
218229
pthread_mutex_lock(&config_mutex); \

0 commit comments

Comments
 (0)