Skip to content

Commit 96d2b34

Browse files
committed
Merge branch 'issue-78' of github.com:sinkcup/wifidog-gateway into remove-hardcoded-servers
Conflicts: src/conf.h
2 parents 24c8e65 + ceae3fd commit 96d2b34

File tree

4 files changed

+69
-13
lines changed

4 files changed

+69
-13
lines changed

src/centralserver.c

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

215-
for (popularserver = popular_servers; *popularserver; popularserver++) {
216-
debug(LOG_DEBUG, "Level %d: Resolving popular server [%s]", level, *popularserver);
217-
h_addr = wd_gethostbyname(*popularserver);
208+
for (popular_server = config->popular_servers; popular_server; popular_server = popular_server->next) {
209+
debug(LOG_DEBUG, "Level %d: Resolving popular server [%s]", level, popular_server->hostname);
210+
h_addr = wd_gethostbyname(popular_server->hostname);
218211
if (h_addr) {
219-
debug(LOG_DEBUG, "Level %d: Resolving popular server [%s] succeeded = [%s]", level, *popularserver,
212+
debug(LOG_DEBUG, "Level %d: Resolving popular server [%s] succeeded = [%s]", level, popular_server->hostname,
220213
inet_ntoa(*h_addr));
221214
break;
222215
} else {
223-
debug(LOG_DEBUG, "Level %d: Resolving popular server [%s] failed", level, *popularserver);
216+
debug(LOG_DEBUG, "Level %d: Resolving popular server [%s] failed", level, popular_server->hostname);
224217
}
225218
}
226219

src/conf.c

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ typedef enum {
9696
oFirewallRule,
9797
oFirewallRuleSet,
9898
oTrustedMACList,
99+
oPopularServers,
99100
oHtmlMessageFile,
100101
oProxyPort,
101102
oSSLPeerVerification,
@@ -140,6 +141,7 @@ static const struct {
140141
"firewallruleset", oFirewallRuleSet}, {
141142
"firewallrule", oFirewallRule}, {
142143
"trustedmaclist", oTrustedMACList}, {
144+
"popularservers", oPopularServers}, {
143145
"htmlmessagefile", oHtmlMessageFile}, {
144146
"proxyport", oProxyPort}, {
145147
"sslpeerverification", oSSLPeerVerification}, {
@@ -189,6 +191,7 @@ config_init(void)
189191
config.internal_sock = safe_strdup(DEFAULT_INTERNAL_SOCK);
190192
config.rulesets = NULL;
191193
config.trustedmaclist = NULL;
194+
config.popular_servers = NULL;
192195
config.proxy_port = 0;
193196
config.ssl_certs = safe_strdup(DEFAULT_AUTHSERVSSLCERTPATH);
194197
config.ssl_verify = DEFAULT_AUTHSERVSSLPEERVER;
@@ -718,6 +721,9 @@ config_read(const char *filename)
718721
case oTrustedMACList:
719722
parse_trusted_mac_list(p1);
720723
break;
724+
case oPopularServers:
725+
parse_popular_servers(p1);
726+
break;
721727
case oHTTPDName:
722728
config.httpdname = safe_strdup(p1);
723729
break;
@@ -900,6 +906,48 @@ parse_trusted_mac_list(const char *ptr)
900906

901907
}
902908

909+
void
910+
parse_popular_servers(const char *ptr)
911+
{
912+
char *ptrcopy = NULL;
913+
char *hostname = NULL;
914+
t_popular_server *p = NULL;
915+
916+
debug(LOG_DEBUG, "Parsing string [%s] for popular servers", ptr);
917+
918+
// max length of domain name is 253 characters
919+
hostname = safe_malloc(254);
920+
921+
/* strsep modifies original, so let's make a copy */
922+
ptrcopy = safe_strdup(ptr);
923+
924+
while ((hostname = strsep(&ptrcopy, ", "))) {
925+
if (strcmp(hostname, "") == 0) {
926+
continue;
927+
}
928+
debug(LOG_DEBUG, "Adding Popular Server [%s] to list", hostname);
929+
930+
if (config.popular_servers == NULL) {
931+
config.popular_servers = safe_malloc(sizeof(t_popular_server));
932+
config.popular_servers->hostname = safe_strdup(hostname);
933+
config.popular_servers->next = NULL;
934+
} else {
935+
p = config.popular_servers;
936+
/* Advance to the last entry */
937+
while (p->next != NULL) {
938+
p = p->next;
939+
}
940+
p->next = safe_malloc(sizeof(t_popular_server));
941+
p = p->next;
942+
p->hostname = safe_strdup(hostname);
943+
p->next = NULL;
944+
}
945+
}
946+
947+
free(ptrcopy);
948+
free(hostname);
949+
}
950+
903951
/** Verifies if the configuration is complete and valid. Terminates the program if it isn't */
904952
void
905953
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
*/
@@ -183,6 +191,7 @@ typedef struct {
183191
t_trusted_mac *trustedmaclist; /**< @brief list of trusted macs */
184192
char *arp_table_path; /**< @brief Path to custom ARP table, formatted
185193
like /proc/net/arp */
194+
t_popular_server *popular_servers; /**< @brief list of popular servers */
186195
} s_config;
187196

188197
/** @brief Get the current gateway configuration */
@@ -211,6 +220,8 @@ t_firewall_rule *get_ruleset(const char *);
211220

212221
void parse_trusted_mac_list(const char *);
213222

223+
void parse_popular_servers(const char *);
224+
214225
#define LOCK_CONFIG() do { \
215226
debug(LOG_DEBUG, "Locking config"); \
216227
pthread_mutex_lock(&config_mutex); \

wifidog.conf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,10 @@ ClientTimeout 5
221221
# Default: none
222222
# Optional
223223
#
224+
225+
# Check DNS health by querying IPs of these hosts
226+
PopularServers kernel.org,ieee.org
227+
224228
# Comma separated list of MAC addresses who are allowed to pass
225229
# through without authentication.
226230
# N.B.: weak security, since MAC addresses are easy to spoof.

0 commit comments

Comments
 (0)