mirror of
https://github.com/pi-hole/FTL.git
synced 2024-10-26 16:52:18 +02:00
595ab259ca
Adjusted tests to fit the current lack of output on the unix socket. Added TELNET enum and used it in place of the old SOCKET to better fit with the rest of the code base. Signed-off-by: Mcat12 <newtoncat12@yahoo.com>
40 lines
1.0 KiB
C
40 lines
1.0 KiB
C
/* Pi-hole: A black hole for Internet advertisements
|
|
* (c) 2017 Pi-hole, LLC (https://pi-hole.net)
|
|
* Network-wide ad blocking via your own hardware.
|
|
*
|
|
* FTL Engine
|
|
* General API commands
|
|
*
|
|
* This file is copyright under the latest version of the EUPL.
|
|
* Please see LICENSE file for your rights under this license. */
|
|
|
|
#include "FTL.h"
|
|
#include "api.h"
|
|
|
|
bool matchesRegex(char *regex_expression, char *input) {
|
|
regex_t regex;
|
|
int result;
|
|
|
|
result = regcomp(®ex, regex_expression, REG_EXTENDED);
|
|
|
|
if(result != 0) {
|
|
logg("Failed to compile regex");
|
|
exit(EXIT_FAILURE);
|
|
}
|
|
|
|
result = regexec(®ex, input, 0, NULL, 0);
|
|
regfree(®ex);
|
|
|
|
return result == 0;
|
|
}
|
|
|
|
bool isValidDomain(char *domain) {
|
|
char *valid_chars_regex = "^((-|_)*[a-z0-9]((-|_)*[a-z0-9])*(-|_)*)(\\.(-|_)*([a-z0-9]((-|_)*[a-z0-9])*))*$";
|
|
char *total_length_regex = "^.{1,253}$";
|
|
char *label_length_regex = "^[^\\.]{1,63}(\\.[^\\.]{1,63})*$";
|
|
|
|
return matchesRegex(valid_chars_regex, domain) &&
|
|
matchesRegex(total_length_regex, domain) &&
|
|
matchesRegex(label_length_regex, domain);
|
|
}
|