@@ -96,6 +96,7 @@ typedef enum {
96
96
oFirewallRule ,
97
97
oFirewallRuleSet ,
98
98
oTrustedMACList ,
99
+ oPopularServers ,
99
100
oHtmlMessageFile ,
100
101
oProxyPort ,
101
102
oSSLPeerVerification ,
@@ -140,20 +141,25 @@ static const struct {
140
141
"firewallruleset" , oFirewallRuleSet }, {
141
142
"firewallrule" , oFirewallRule }, {
142
143
"trustedmaclist" , oTrustedMACList }, {
144
+ "popularservers" , oPopularServers }, {
143
145
"htmlmessagefile" , oHtmlMessageFile }, {
144
146
"proxyport" , oProxyPort }, {
145
147
"sslpeerverification" , oSSLPeerVerification }, {
146
148
"sslcertpath" , oSSLCertPath }, {
147
149
"sslallowedcipherlist" , oSSLAllowedCipherList }, {
148
150
NULL , oBadOption },};
149
151
150
- static void config_notnull (const void * parm , const char * parmname );
152
+ static void config_notnull (const void * , const char * );
151
153
static int parse_boolean_value (char * );
152
154
static void parse_auth_server (FILE * , const char * , int * );
153
- static int _parse_firewall_rule (const char * ruleset , char * leftover );
155
+ static int _parse_firewall_rule (const char * , char * );
154
156
static void parse_firewall_ruleset (const char * , FILE * , const char * , int * );
157
+ static void parse_trusted_mac_list (const char * );
158
+ static void parse_popular_servers (const char * );
159
+ static void validate_popular_servers (void );
160
+ static void add_popular_server (const char * );
155
161
156
- static OpCodes config_parse_token (const char * cp , const char * filename , int linenum );
162
+ static OpCodes config_parse_token (const char * , const char * , int );
157
163
158
164
/** Accessor for the current gateway configuration
159
165
@return: A pointer to the current config. The pointer isn't opaque, but should be treated as READ-ONLY
@@ -189,6 +195,7 @@ config_init(void)
189
195
config .internal_sock = safe_strdup (DEFAULT_INTERNAL_SOCK );
190
196
config .rulesets = NULL ;
191
197
config .trustedmaclist = NULL ;
198
+ config .popular_servers = NULL ;
192
199
config .proxy_port = 0 ;
193
200
config .ssl_certs = safe_strdup (DEFAULT_AUTHSERVSSLCERTPATH );
194
201
config .ssl_verify = DEFAULT_AUTHSERVSSLPEERVER ;
630
637
config_read (const char * filename )
631
638
{
632
639
FILE * fd ;
633
- char line [MAX_BUF ], * s , * p1 , * p2 ;
640
+ char line [MAX_BUF ], * s , * p1 , * p2 , * rawarg = NULL ;
634
641
int linenum = 0 , opcode , value ;
635
642
size_t len ;
636
643
@@ -666,7 +673,7 @@ config_read(const char *filename)
666
673
break ;
667
674
len = strlen (p1 );
668
675
}
669
-
676
+ rawarg = safe_strdup ( p1 );
670
677
if ((p2 = strchr (p1 , ' ' ))) {
671
678
p2 [0 ] = '\0' ;
672
679
} else if ((p2 = strstr (p1 , "\r\n" ))) {
@@ -718,6 +725,9 @@ config_read(const char *filename)
718
725
case oTrustedMACList :
719
726
parse_trusted_mac_list (p1 );
720
727
break ;
728
+ case oPopularServers :
729
+ parse_popular_servers (rawarg );
730
+ break ;
721
731
case oHTTPDName :
722
732
config .httpdname = safe_strdup (p1 );
723
733
break ;
@@ -785,6 +795,10 @@ config_read(const char *filename)
785
795
}
786
796
}
787
797
}
798
+ if (rawarg ) {
799
+ free (rawarg );
800
+ rawarg = NULL ;
801
+ }
788
802
}
789
803
790
804
if (config .httpdusername && !config .httpdpassword ) {
@@ -817,7 +831,8 @@ parse_boolean_value(char *line)
817
831
return -1 ;
818
832
}
819
833
820
- /* Parse possiblemac to see if it is valid MAC address format */
834
+ /**
835
+ * Parse possiblemac to see if it is valid MAC address format */
821
836
int
822
837
check_mac_format (char * possiblemac )
823
838
{
@@ -828,7 +843,10 @@ check_mac_format(char *possiblemac)
828
843
hex2 , hex2 , hex2 , hex2 , hex2 , hex2 ) == 6 ;
829
844
}
830
845
831
- void
846
+ /** @internal
847
+ * Parse the trusted mac list.
848
+ */
849
+ static void
832
850
parse_trusted_mac_list (const char * ptr )
833
851
{
834
852
char * ptrcopy = NULL ;
@@ -843,7 +861,7 @@ parse_trusted_mac_list(const char *ptr)
843
861
/* strsep modifies original, so let's make a copy */
844
862
ptrcopy = safe_strdup (ptr );
845
863
846
- while ((possiblemac = strsep (& ptrcopy , ", " ))) {
864
+ while ((possiblemac = strsep (& ptrcopy , "," ))) {
847
865
/* check for valid format */
848
866
if (!check_mac_format (possiblemac )) {
849
867
debug (LOG_ERR ,
@@ -900,19 +918,90 @@ parse_trusted_mac_list(const char *ptr)
900
918
901
919
}
902
920
921
+ /** @internal
922
+ * Add a popular server to the list. It prepends for simplicity.
923
+ * @param server The hostname to add.
924
+ */
925
+ static void
926
+ add_popular_server (const char * server )
927
+ {
928
+ t_popular_server * p = NULL ;
929
+
930
+ p = (t_popular_server * )safe_malloc (sizeof (t_popular_server ));
931
+ p -> hostname = safe_strdup (server );
932
+
933
+ if (config .popular_servers == NULL ) {
934
+ p -> next = NULL ;
935
+ config .popular_servers = p ;
936
+ } else {
937
+ p -> next = config .popular_servers ;
938
+ config .popular_servers = p ;
939
+ }
940
+ }
941
+
942
+ static void
943
+ parse_popular_servers (const char * ptr )
944
+ {
945
+ char * ptrcopy = NULL ;
946
+ char * hostname = NULL ;
947
+ char * tmp = NULL ;
948
+
949
+ debug (LOG_DEBUG , "Parsing string [%s] for popular servers" , ptr );
950
+
951
+ /* strsep modifies original, so let's make a copy */
952
+ ptrcopy = safe_strdup (ptr );
953
+
954
+ while ((hostname = strsep (& ptrcopy , "," ))) { /* hostname does *not* need allocation. strsep
955
+ provides a pointer in ptrcopy. */
956
+ /* Skip leading spaces. */
957
+ while (* hostname != '\0' && isblank (* hostname )) {
958
+ hostname ++ ;
959
+ }
960
+ if (* hostname == '\0' ) { /* Equivalent to strcmp(hostname, "") == 0 */
961
+ continue ;
962
+ }
963
+ /* Remove any trailing blanks. */
964
+ tmp = hostname ;
965
+ while (* tmp != '\0' && !isblank (* tmp )) {
966
+ tmp ++ ;
967
+ }
968
+ if (* tmp != '\0' && isblank (* tmp )) {
969
+ * tmp = '\0' ;
970
+ }
971
+ debug (LOG_DEBUG , "Adding Popular Server [%s] to list" , hostname );
972
+ add_popular_server (hostname );
973
+ }
974
+
975
+ free (ptrcopy );
976
+ }
977
+
903
978
/** Verifies if the configuration is complete and valid. Terminates the program if it isn't */
904
979
void
905
980
config_validate (void )
906
981
{
907
982
config_notnull (config .gw_interface , "GatewayInterface" );
908
983
config_notnull (config .auth_servers , "AuthServer" );
984
+ validate_popular_servers ();
909
985
910
986
if (missing_parms ) {
911
987
debug (LOG_ERR , "Configuration is not complete, exiting..." );
912
988
exit (-1 );
913
989
}
914
990
}
915
991
992
+ /** @internal
993
+ * Validate that popular servers are populated or log a warning and set a default.
994
+ */
995
+ static void
996
+ validate_popular_servers (void )
997
+ {
998
+ if (config .popular_servers == NULL ) {
999
+ debug (LOG_WARNING , "PopularServers not set in config file, this will become fatal in a future version." );
1000
+ add_popular_server ("www.google.com" );
1001
+ add_popular_server ("www.yahoo.com" );
1002
+ }
1003
+ }
1004
+
916
1005
/** @internal
917
1006
Verifies that a required parameter is not a null pointer
918
1007
*/
0 commit comments